OK I can't stop the tradition so are first program in C++ will be of course "Hello World".
OK let's get started.
Hope that was easy enough.Code:#include<iostream> // This includes the files for input and output. int main() //Inside this is where the computer executes the code. { std::cout << "Hello World" << std::endl; //This prints Hello World, cout pronounced C out sends Hello World to the console window. //endl which stands for endline puts us on the beginning of the next line if you want to stay on the same line then just don't add std::endl just the ";" after your text. // std stands for standard which just tells the computer that this is a standard operation. system("PAUSE");//This makes the window stay up without this the window would open and shut in a flash.(This is not a good way to do that I'll show you how to fix it next.) return 0;//This ends the program. }
Now I'm going to show you how to save some time righting a story or paragraph and a better way to keep the window open.
At first I didn't want to use the namespace std thing because I thought it was bad programming but it will save you a lot of work if you have a lot of sentences to type.Code:#include<iostream> // This includes the files for input and output. using namespace std; //This now includes the standard files(I think:{)so in are Hello World line we don't have to type std:: before cout and endl. int main() //Inside this is where the computer executes the code. { cout << "Hello World" << endl; //This prints Hello World, cout pronounced C out sends Hello World to the console window. //endl which stands for endline and puts us on the beginning of the next line if you want to stay on the same line then just don't add endl just the ";" after your text. cin.get();//This is a better way to make the window stay up(Note this only works if you include namespace std; return 0;//This ends the program. }
Well I hope this tutorial helped you.
(if you have any problems PM me or leave a visitor message sorry but I don't know how to make the code windows bigger)
Last edited by CommittedC0der; 12-14-2009 at 06:45 PM.
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.
Nice, I will wait for your next posts
thanks
Thanks,guys.
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.
Good first tutorial!
if i may make some suggestions though.
std is the standard namespace where standard functions/operations are stored.Code:// std stands for standard which just tells the computer that this is a standard operation.
this line tells the compiler that your are implicitly using the std namespace therefore you can call any function inside of the std namespace without having to explicitly let the compiler know what namespace you are using.Code:using namespace std; //This now includes the standard files(I think:{)so in are Hello World line we don't have to type std:: before cout and endl.
also implicitly using a namespace is not bad programming but it has it's advantages and disadvantages.
an advantage is as you have shown makes it so that you can use functions without having to prefix it with the namespace(std::cout changes to cout).
but lets say you wanted to make your own function called cout if you were to use the namespace std then you would need to name your function something else. whereas if you did not implicitly use the std namespace then you could have your own cout function and keep the std::cout function.
another disadvantage of implicitly using a namespace is code readability meaning how well humans can read your code.
but if your just using the std namespace then you don't need to worry about that since the std is very common and easily recognizable.
so implicitly using a namespace is all up to you the programmer.
if you don't need to make a function that has the same name as in the namespace then go ahead and use it. it will only help you to code faster
hopefully that all makes sense my grammar sucks
like i said good tutoriallook forward to more from you
![]()
Thanks for the info good to know.![]()
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.
yup
Thank you! Nice Tut!
nice post.. looking forward to the next ones![]()
Thanks.![]()
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks