CIN judgment Read End C + + language

Source: Internet
Author: User

CIN is a C + + input stream that can be read by >>.

Judging the end of reading, there are generally two methods, depending on the contract with the input.

1 ends with a special value.

If you enter an integer, ending with-1, then when you read-1, make sure the read is finished.

Code:

int n; while (1) {      cin>>n;      if (n == -1) break ;      //处理输入的合法值。

}

2 ends with EOF, which is the file terminator.

This approach applies to file as input, or the keyboard to manually enter a file terminator as the end tag.

Code:

int n; while (cin>>n) {      //处理输入的合法值。

}

The way to enter EOF on Windows is CTRL + Z

The method of entering EOF on other platforms is Ctrl+d

CIN judgment Read End C + + language

Related Article

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.