About C + + reads variable amounts of input data

Source: Internet
Author: User
About C + + reads variable amounts of input data
#define _crt_secure_no_warnings 1#include <iostream>int main () {int sum = 0, value = 0;//reads data until the end of the file, computes the sum of all read-in values and WHI Le (std::cin >> value) sum + = value; Equivalent to Sumsum = sum + value std::cout << "sum is:" << sum << std::endl;system ("pause"); return 0;}

When an invalid character is entered or a file terminator is encountered, the loop ends.

Problem:

How do I enter a file terminator from the keyboard?

For Windows systems, enter the file terminator by Ctrl + Z, and then press ENTER.

Unix system, enter the file terminator method is CTRL + D


This article is from the "Learning Records" blog, so be sure to keep this source http://10794428.blog.51cto.com/10784428/1839025

About C + + reads variable amounts of input data

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.