Learning C++: What is basic input output operations in C++?

Pages

Friday, August 19, 2011

What is basic input output operations in C++?

Hope you tried Hello world program, and at least got a idea how C++ programs looks like.

Now its time to learn basic input output operations in C++.
With few suggestions now i am improving my blogging skills. So I suggest you all my readers to please comment, like review of post, or is my posts are beneficial for you or not??

To learn Basic Input Output operation in C++ first you need to clear your concept of C++ most useful object i.e. "cin" and "cout".

1) cin object is use to take input from keyboard, its always associated with its operator sign >> , after this sign you need to specify variable name.
Example: cin>>VariableName

2) cout object is use to display content of variable or custom message to screen, its serves as output operation. It is also associated with operator sign << , after this message or variable is used to specify.
Example: cout<<"Hi";

Now here is program with C++ basic input / out operation.

In below program, we will show message and save number in integer variable "no1".

#include<stdio.h>
#include<iostream.h>
void main()
{
    int no1;
    cout<<"Enter number: ";  // Show message
    cin>>no1;  //Save Integer value in variable no1
    
    //Showing number which was entered by user
    cout<<"You have entered "<<no1;
    getch();
}

Now notice while showing variable value using cout,  we have used operator  << twice, this is because first operator << will show our custom message and second << will show value of  no1.

Run this program using run option of your IDE and enjoy. If you have any doubt comment me.
Enjoy Coding :)

No comments:

Post a Comment