java - 急等。vs写一个简单程序关闭黑窗老是响应很久,然后报错,无法再次运行
迷茫
迷茫 2017-04-18 10:52:18
0
2
518

后台进程里一直还关不了这个运行台程序,每次都要退出重进,怎么解决啊?


#include "stdafx.h"
#include "iostream"
#include <cstdlib>
using namespace std;


int main()
{
    int n = 1;
    cout << n;
    int nn= 3;
    cout << nn;
    int a[4];
    for (int i = 0;i < 4;i++)
    {
        a[i] = i;
    }
    for (int i = 0;i < 4;i++)
    {
        cout << a[i];
    }
    system("PAUSE");
    return 0;
}
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

Antworte allen(2)
黄舟

system("PAUSE");按下任意键继续

然而有1次你没有输入任何键,那么return 0;就没有运行,进程没有被关闭。你又再次用VS编译就会出现这个情况。

重启电脑后,使用 getch(); 这种输入字符的命令代替system("PAUSE");试试。

刘奇
#include <iostream>
#include <cstdlib>

using namespace std;
int main()
{
    int n = 1;
    cout << n;
    int nn= 3;
    cout << nn;
    int a[4];
    for (int i = 0;i < 4;i++)
    {
        a[i] = i;
    }
    for (int i = 0;i < 4;i++)
    {
        cout << a[i];
    }
    return 0;
}

略作修改在G++ 环境下一切正常。

现在测试下VS环境。

更新:

VS2015 环境下一切正常。

请题主提供更多一些的信息。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!