Posted in C++, Home, TUTORIALS

C++ Tutorials: 4 – Iostream part 2

Last time we saw : Introduction to iostream, Hello World!

Today we are going to complete this part, introducing some important information.


A variable is an allocation of memory used to store a value. There are diffrent types of variables in c++, some primitive types are:

  • int
  • float
  • double
  • char
  • boolean

There are also some other types just like “string” that have to be included in order to use them.

Last time we made a simple HelloWorld program that prints out “HelloWorld” on the screen, today we’ll do something more interesting.

  1. // this is a comment, not seen by compiler
  2. /* block comment
  3.      in more lines */
  4. #include <iostream>
  5. using namespace std;
  6. int age;
  7. int main(){
  8. cout << “Insert your age.. ” ;
  9. cin >> age;
  10. cout << “Your age is: ” << age << endl;
  11. }

Let’s analyse first line.

  • It is a single line comment, you open it using //

Let’s analyse 2nd and 3rd lines.

  • It is a block comment, you open it using /* and close it with */

Let’s analyse 6th line.

  • We have created an integer variable, named age, inwhich we’ll store our age.

Let’s analyse 9th line.


  • Meaning: get user input, and store this input into a variable
  • Syntax: cin >> nameofvariable

Let’s analyse 10th line.

  • Display the result using a concatenated string.


See you next time!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s