1.2.2 A program that uses the IO library
3. Read the Inflow
- Input operator >>:
- The left operand is an instantiated object of the IStream class type CIN
- Right operand is a variable of C + + built-in type
- For example std::cin>> v1 >> v2
- The function is to read the data from the IStream, then save to the variables V1 and v2, the return value is the instantiation object of the IStream class type CIN
1.4.4 input of the read-in Unknown
- You can use the instantiated object of the IStream class type Cin as a condition for the judgment of an if or while statement,
- For example while (STD::CIN>>V1)
- Here, std::cin>>v1, after the expression executes, will you get a return value, or std::cin
- If Std::cin is a condition, the state of the stream is tested,
- If the stream is valid, it is possible to read the next data, and you can assume that the value of Std::cin is True
- If a file terminator is encountered, the value of std::cin is assumed to be false
- In the actual program debugging process, enter 1 2 3 in the terminal, then the carriage return, and then enter CTRL + D (file terminator),
- When input 1 o'clock, STD::CIN>>V1, the return value is Std::cin, at this time to judge, read into the next data is possible? Because the next data is 2, it is possible, so the value of std::cin is considered true
- When input is 2 o'clock,
- When input is 3 o'clock, the return value is Std::cin, judging the next data is ctrl+d, erase, is the file terminator, then the value of Sorry,std::cin is considered false,
Chapter I. (2)