Usage of CIN and cout (header file is <iostream>)

Source: Internet
Author: User

One: standard input function cin

It represents the standard input device-the keyboard, which belongs to the stream, and his usage is the same as that of the stream. That is, the:cin>> variable; Enter multiple variables that can be written on one line, such as:cin>>x>>y>>z; This is not good to read, generally in the front of the input statement, you have to do a hint, "Please enter XXX".

In addition, this function does not have the address symbol "&", also does not have to write the variable type, must not confuse with scanf. Of course, it does not check whether variable input is legal. Such as:

int i;

cout<< "Please input a number:"

cin>>i;

cout<< "i=" <<i<<endl;

If you enter a word such as ' a ' then he does not check, but the result of your output is not correct, this should be checked by hand. Of course he's like scanf. If you enter an illegal variable value inside the loop, you will also get into a dead loop. As follows:

/* An example of entering an illegal variable into a dead loop */

Endl is a manipulator (manipulator) in the C + + standard library, included in <iostream> (<iostream>), Namespace (namespace): Std. Note Endl (for the letter L) rather than end1 (number 1).
Meaning: A line of output ends, then output the next line full name: End of lines
Endl English means end of line, which is the end of a row of output, then output the next line.


Usage of CIN and cout (header file is <iostream>)

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.