Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link
Posts

5.2 cin (input stream)

1 min read
Image result for cin (input stream) C++
In most program environments, the standard input by default is the keyboard, and the C++ stream object defined to access it is cin. cin is an instance of iostream class

For formatted input operations, cin is used together with the extraction operator, which is written as >> (i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored. For example:
int age;
//declares a variable of type int called age
cin >> age;
//extracts a value to be stored in it

This operation makes the program wait for input from cin; generally, this means that the program will wait for the user to enter some sequence with the keyboard.

Extractions on cin can also be chained to request more than one datum in a single statement:
cin >> a >> b;

This is equivalent to:
cin >> a;
cin >> b;
In both cases, the user is expected to introduce two values, one for variable a, and another for variable b. Any kind of space is used to separate two consecutive input operations; this may either be a space, a tab, or a new-line character.

                      5.3 cerr (error stream)          NEXT >>

You may like these posts

  • On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. cout is an instance of iostream class …
  • The predefined object clog is an instance of ostream class. The clog object is said to be attached to the standard error device, which is also a display screen but the object…
  • In most program environments, the standard input by default is the keyboard, and the C++ stream object defined to access it is cin. cin is an instance of iostream class For f…
  • if statement An if statement contains a Boolean expression and block of statements enclosed within braces. Structure of if statement if (boolean expression ) /* if expression …
  •   A switch statement is used instead of nested if...else statements. It is multiple branch decision statement of C++. A switch statement tests a variable with list of val…
  • The predefined object cerr is an instance of iostream class. The cerr object is said to be attached to the standard error device, which is also a display screen but the objec…

Post a Comment