Chapter I. (2)

Source: Internet
Author: User

1.2.2 A program that uses the IO library

3. Read the Inflow

  1. Input operator >>:
    1. The left operand is an instantiated object of the IStream class type CIN
    2. Right operand is a variable of C + + built-in type
    3. For example std::cin>> v1 >> v2
    4. 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

  1. You can use the instantiated object of the IStream class type Cin as a condition for the judgment of an if or while statement,
  2. For example while (STD::CIN>>V1)
    1. Here, std::cin>>v1, after the expression executes, will you get a return value, or std::cin
    2. If Std::cin is a condition, the state of the stream is tested,
      1. 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
      2. If a file terminator is encountered, the value of std::cin is assumed to be false
  3. In the actual program debugging process, enter 1 2 3 in the terminal, then the carriage return, and then enter CTRL + D (file terminator),
    1. 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
    2. When input is 2 o'clock,
    3. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.