Why C + + Why code execution appears a black box (command Window) a flash over the workaround

Source: Internet
Author: User

VS2012 after the input code executes, the screen flashes over and the display box does not appear:

#include <iostream>
int main ()
{
using namespace Std;
const int arsize = 20;
Char Name[arsize];
Char Dessert[arsize];

cout << "Enter your name:\n";
Cin.getline (name,arsize);
cout << "Enter your favorite dessert:\n";
Cin.getline (dessert,arsize);
cout << "I have some delicious" <<dessert;
cout << "For You," <<name<< ". \ n";
return 0;
}

There is no black box (command-line window) because it finished ... cout << "for You," <<name<< ". \ n", then return directly to 0, which is executed, so it will close, So you can add a system ("pause") before return, and you may see the output. The following procedures are followed:

#include <iostream>
int main ()
{
using namespace Std;
const int arsize = 20;
Char Name[arsize];
Char Dessert[arsize];

cout << "Enter your name:\n";
Cin.getline (name,arsize);
cout << "Enter your favorite dessert:\n";
Cin.getline (dessert,arsize);
cout << "I have some delicious" <<dessert;
cout << "For You," <<name<< ". \ n";
System ("pause");
return 0;
}

Why C + + Why code execution appears a black box (command Window) a flash over the workaround

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.