A very simple C++ code sample on how to use cin, to read from the standard input


Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

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: Reading input of integers from standard input using cin in C++ programming

To show: How to use cin to read integers from standard input in C++ programming




// the stream extraction operator variation of cin

#include <iostream>

using namespace std;


int main(void)


int x, y;


cout<<"Enter two integers: ";


cout<<x<<(x == y?" is " : " is not ")<<"equal to "<<y<<endl;


return 0;



Output example:


Enter two integers: 77 71

77 is not equal to 71

Press any key to continue . . .

Enter two integers: 11 11

11 is equal to 11

Press any key to continue . . .



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