C + + cout<< cin>> Comment

Source: Internet
Author: User

Std::cout is an object in the Ostream type in the #include<iostream> library

STD:: Represents a namespace, all names defined by the standard library are in the namespace Std

Std::cout is an object in the IStream type in the #include<iostream> library

std::cout<<a<<std::endl;

The << in the previous statement is the input operator, which is to get the amount of the head over there into the object referred to by the arrow and return the object that the arrow after the operation refers to.

Std::endl is a manipulator that ends the current line and brushes the contents of the buffer associated with the device to the device, preferably with a endl for each cout to clear the cache.

std::cin>>a>>b;

In Cin, when an invalid input is encountered, such as CIN>>V1>>V2,V1 is int, you enter a, it returns an invalid state, and the subsequent V2 cannot be entered. Or when a file terminator is encountered, an invalid state is returned.

End of file in Window System by CTRL + Z type, Linux by Ctrl+d type

The above features can be used to read a variable amount of input data.

#include <iostream>using namespace Std;int main () {int sum = 0, value = 0;while (cin >> value) {sum + = value;} cout << Sum<<endl;return 0;}

  

PS: annotations cannot be nested

C + + cout<< cin>> Comment

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.