C++ Programming & Tutorials for Beginners

Input/Ouput Statements

Home  »  C++ Programming  »  Input/Ouput Statements


     cin and cout are the two predefined objects which represent standard input and output stream. The standard output stream represents screen where as the standard input stream represents the keyboard. These objects are the members of iostream class. Hence the header file < iostream.h > should be included in the beginning of all the programs in C++.

Example Program


Output:




The operator << is called insertion operator and the operator >> is called the extraction operator. It is possible to give input for more than one variable in the same cin statement. Output for more than one variable can also be displayed from using a single cout statement.

Standard Output (cout)

    The cout is used to display an object onto the video screen. The insertion operator << is used along with the cout statement. The general syntax of cout statement is:

cout<< variabl1<< variable2<<...........cout<< variableN;

Standard Input (cin)

    The cin statement is used to read a number, a character or a string of characters from a standard input device, normally the keyboard. The extraction operator >> is used with cin statement. The general syntax of cin statement is:

cin>>variable1>>variable2>>.........variableN;



Standard Ouput endl

    The endl is an output manipulator used in C++ programs to generate a carriage return or line feed character. This function may be used serverl times in a single statment. For example:

cout<<"a"<< endl<<"B"<< endl;
The endl function is same as the non-graphic character used in simple c language programs.


Previous
Next Post »