Introduction to C++
Introduction to C++
Hey there, In this article I will be talking a bit about the C++ language..
So you ask what's C++, Well is C++ was originated from the programming language C. C++ is the enhanced version of C providing object-oriented programming.
Ok let's start.
To start up a project u need a C++ compiler there are quite a few c++ compilers out I myself use devC++ and Microsoft visual c++ 6 there are others such as borland and turboC++, for beginner I recommend VC++ 6.
To make comments within your C++ program u use the following syntax "//comment comes here" Comments are usefull for good programming.
To start a project u use the line "#include <iostream>"
Iostream is a header file which is used for Input/output in the C++ programming language
Next we user "using namespace std;" All the elements of the standard C++ library are declared within what is called a namespace
and finally "int main()"
So now we have the following
#include <iostream> using namespace std; int main() { }
That is the basic outlook of a program now let's start coding
We are gonna make a simple program to display the age of the use…
We will use the following two statements cin and cout
Cin = Consol input(get's what the user enters) Cout = Consol output(display's what the user entered)
Ok so now we will want to declare a integer called age doing so we use the following syntax
int age = 0;
Now we have the integer age we will want to get what the user enters u use the following to get the data from what the user enters
cin >> age;
We use the ; to end a statement that we have made.
Now to display what the user enter we will use
cout << age << endl;
endl; = Ends the current line.
So the code would look as following
#include <iostream> using namespace std; int main() { int age = 0; cout << "Please enter your age: "; //We want the user to enter his/hers age. cin >> age; //Here we get what the user enters cout >> "Your age is: " >> age >> endl; return 0; }
Ok so those are the basics on C++ and remeber when outputting a variable not to use the quotes or else it will just output what u entered as the variable name…
Thank you for taking your time and reading:)
- Nightfox
bl4ckc4t 18 years ago
Im not an expert on C++ but iostream is for cout. its a header that makes cout more efficient.
ghost 18 years ago
never explained: what a comment is about ; why we need to declare variables what return is/does
if you want to do an introduction tutorial you should start with a simple hello world ;)
ghost 18 years ago
never explained: what a comment is. about ";". why we need to declare variables. what return is/does. if you want to do an introduction tutorial you should start with a simple hello world. (sorry had to post again because the last one looked like shit
ghost 18 years ago
Nice tutorial. :) But line 8 of your code should have the arrows facing the opposite way for cout. Besides that, great work!:happy:
ghost 18 years ago
if someone will start learning from such a poorly written article, he has no future in programming. you even got the cout wrong. whats good in someone who knows how to do a hello world proggie but doesnt know what every line does.
ghost 18 years ago
What the fuck, this is the biggest piece of shit article ever. You only tell half-truths about everything, one example is "std::endl; <== ends the line". My fucking dog could have told you that by GUESSING. std::endl; prints out a newline character and than flushes the output buffer. Learn the fucking language before you try and teach others. kkthxbai