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

  • Russia Ukraine Crisis: Ukraine has rejected Russian suggestions that it was refusing to negotiate a ceasefire but said it was not ready to accept unacceptable conditions Russia no…
  • A file is collection of related records, a record is composed of several fields and field is a group of character. This requires another standard C++ library called fstream which…
  • Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers. C++ exception h…
  • A string is simply an array of characters which is terminated by a null character '\0' which shows the end of the string. Strings are always enclosed by double quotes. Whe…
  • The service was activated 10 hours after Ukrainian Minister of Digital Transformation Mykhailo Fedorov urged Elon Musk to provide Starlink services to Ukraine Elon Musk said Starl…
  • Constants refer to fixed values in the code that you can't change and they are called literals. Constants can be of any of the basic data types and can be divided into Integer l…

Post a Comment