C + + console flashed through

Source: Internet
Author: User

Many beginners of C + + will start from the console, but the code is often flashed over, (some compilers will not have such a situation).

For example:

#include <iostream>using namespace Std;//main function is a program's entry//int is an integer type (integer)//main The return value of the function is an integer type, So to declare the return type (int) int main () {    cout<< "Hello world!" before the function name <<endl;    Cout is provided by the standard library, so introduce namespaces: using namespace std;    And Endl is a newline, ie (End line)    //code from <a target=_blank href= "http://blog.csdn.net/imcjysy/article/details/43838459" >http://blog.csdn.net/imcjysy/article/details/43838459</a>, a C + + Hello World Program}

The program compiles a black window that flashes past, and we call it a console.

Many beginners are stuck here, this is not a problem with the code, is not a compiler bug,

Workaround:

Add a cin.get () in the main function;

The function of Cin.get is to read the carriage return at the end of the line.

Now the program will not flash past.

Attention:

Some places with a cin.get (), not enough, need to use two. (only a few cases)



C + + console flashed through

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.