输出到windows cmd提示符

Output to windows cmd prompt

本文关键字:提示符 cmd windows 输出      更新时间:2023-10-16

我被告知制作一个将输出5行的exe文件。我得到了这样的指示:

程序运行后不能挂起。我将在命令行执行它,并期望它在程序完成时结束。

我试着去属性->链接器->系统->控制台。当我按ctrl-f5键时,它似乎按他的意思做了。然后我做了一个exe,现在它消失了,它没有打印到控制台。

我正在使用一个简单的计数程序,例如:

int main()
{
    cout<<"hello"<<endl;
    return 1;
}

编辑我正在使用visual studio 2013,我从命令行运行。注意,我不是要求窗口保持打开状态,而是要求打印到控制台本身。我没有按ctrl-f5,而是转到cmd.exe,然后转到可执行文件。我已经尝试了发布版本和调试版本。

如果我理解了你的问题。尝试以下方法并将有用的部分添加到代码中。不需要的行被注释掉。

// ConsoleApplication1.cpp : Defines the entry point for the console application.
// (Just 2 ways to wait, befoore command-line console vanishes.)
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    cout << "It's Foo's Bar!n";
    system("pause"); //preferred way.
    //cin.get(); //2nd way, not as good.
    return 0;
}