The C++ formatted input and output using the standard console output, cout (<<) and console input, cin (>>) code sample

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: To format the input and output using the standard console output, cout (<<) and console input, cin (>>) in C++ programming

To show: How to use the standard console output, cout (<<) and console input, cin (>>) in C++ programming

 

 

 

#include <iostream>

using namespace std;

 

void main(void)

{

int p, q, r;

 

cout << "Enter 3 integers separated by space: \n";

cin>>p>>q>>r;

 

// the >> operator skips whitespace characters such as tabs,

// blank space and newlines. When eof is encountered, zero (false) is returned.

cout<<"Sum of the "<<p<<","<<q<<" and "<<r<<" is = "<<(p+q+r)<<endl;

return;

}

 

Output example:

 

Enter 3 integers separated by space:

12 23 34

Sum of the 12,23 and 34 is = 69

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index