2.10 SIMPLE INPUT–OUTPUT

2.10.1 Input–output with cin and cout

C++ has introduced simple to use objects like cin and cout for handling input–output. Objects cin and cout represent input stream and output stream, respectively. The cin represents standard input, usually keyboard, corresponding to stdin in C. Similarly, cout represents standard output, usually screen, corresponding to stdout in C. These are stream objects. Along with operators << and >> they allow programmer to handle input–output in very simplified manner. Figure 2.1 depicts pictorially this fact.

If we want to read any variable say int marks from keyboard, we have to say

cin >> marks;

 

 

Figure 2.1 Iostreams

 

If we want to write any variable say float money on the screen, ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.