• 15
• 15
• 11
• 9
• 10

# Total Begginer C++ Tutorial

This topic is 4922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

To all C++ beginners / total C++ nOOB’s, I have been reading many posts asking for a simple C++ beginners tutorial, so I thought that I would wright my own tutorial. Ok, welcome to the C++ beginners / total C++ nOOB tutorial. Congratulations, you have chosen the most widely used programming language in the world at the moment. C++ is not only an industry standard for game developers, but for software developers as well. This short tutorial is designed to teach you the basics of C++. Shall we begin? So basically, computers are whiny crybabies that need to be told exactly what to do in the exact order that you want them to do it. That’s right, if you don’t tell them, it won’t happen. First of all, you need to tell the computer what tool’s it will need, like telling someone what materials they will need for a certain project. That is where we get "#include" commands. Your telling the computer what it will need to "include" to carry out the other instructions. Some basic examples of these "#include" are: #include <string> - This lets the programmer use strings in his / her main code #include <cstdio> - This is telling the computer to include the "C Standard Input / Output" #include <cstdlib> - This is telling the computer to include the "C Standard Library" #include <iostream> - This is telling the computer to include the "Input / Output Stream" (You can tell that programmers LOVE acronyms) Another common command that you must tell the computer is the "using namespace std;" command. After telling the computer what you need to include, you must set up the basic structure of the program. In simple programs you start with "int main()." After the "int main," you open the program and close the program with braces:
#include <iostream>
using namespace std;

int main()

{

}


In between the brackets, you would include all of your code. To instruct the computer to display text on the screen, you would use "cout." "cout" stands for C++ Output. Right now, the text is going to appear on the console screen. The console screen is basically a DOS window. Here is an example of displaying text on a console screen:
#include <iostream>
using namespace std;

int main()

{

cout << "This text will appear on the console screen!" << endl;

return 0;

}


// This is an example of a comment, you should add comments to your code as much as
// possible so that you can figure out what you were thinking of later

#include <iostream>
#include <cstdlib> // in order to use getchar(); you must include the C++ Standard Library
using namespace std;

int main()

{

cout << "This text will appear on the console screen, and you can read it!" << endl;
getchar();

return 0;

}


// A program that asks for your name using C Input

#include <iostream>
#include <string>
using namespace std;

int main()

{

string name;

cout << "What is your name?" << endl;
cin >> name;

return 0;

}


This program only displays, "What is your name?" Then it asks you for your name and then closes. If you would like to display an inputted variable, you would use "cout <<" followed by the string name and ending with "<< endl;" You can clear the console screen by using the "system("cls");" command. The following example does just that:
// A program that asks for your name using input,
// then displays your name using output
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main()

{

string name;

cout << "What is your name?" << endl;
cin >> name;

system("cls");

cout << "Nice to meet you ";
cout << name << endl;
system("PAUSE");

return 0;

}


As you can see, if you do not end the line using "endl;" then the next "cout" stays on the same line. In this case, getchar(); will not pause the screen, so we must use system("PAUSE"); You have now learned the fundamental basics of C++. I encourage you to keep learning and to keep programming! [Edited by - NoWhereMan on September 30, 2004 8:51:29 PM]

##### Share on other sites
[cool] OMG! Thx dood! I am now a l33t haxoR!!11 [cool]

Seriously, I thought it was pretty good. Maybe you should have spend a little more time explaining the notion of variables, I don't know how fast a noob can understand that.

##### Share on other sites
Quote:
 Original post by mikemanSeriously, I thought it was pretty good. Maybe you should have spend a little more time explaining the notion of variables, I don't know how fast a noob can understand that.

Ok thanks alot, I'll take your advice and try to fix that.

##### Share on other sites
Well, I'm just trying to teach c++ to a friend of mine.
Might refer him to this thread as well ;)

btw. : cstdio = c standard IO not c studio =)

##### Share on other sites
{ } are called braces, curly braces or curly brackets.
[ ] are called brackets.
( ) are called parenthesis.

Might want to clean that part up, the rest of it looks good though. Good job!

##### Share on other sites
Thanks for the advice everyone, I have fixed most of my mistakes. I'm glad that people like my tutorial. ;)

##### Share on other sites
Should I make another tutorial, a more advanced one?

##### Share on other sites
To use string, include string :) You didn't do that in your example.

##### Share on other sites
Quote:
 Original post by EriondTo use string, include string :) You didn't do that in your example.

EDIT: Sry my mistake, there will be a compiler error if you are using VS6.

[Edited by - NoWhereMan on September 30, 2004 5:37:22 PM]