[英]Output to windows cmd prompt
I have been told to make an exe file that will output 5 lines. 我被告知要制作一个将输出5行的exe文件。 I have been given these instructions:
我得到了这些指示:
Your program must not hang after running. 您的程序在运行后一定不能挂起。 I will execute it at command-line and will expect it to finish when the program is done.
我将在命令行中执行它,并期望在程序完成时完成它。
I tried going to properties -> linker -> system - > console. 我尝试去属性->链接器->系统->控制台。 It seemed to do what he wanted when I ran ctrl-f5.
当我运行ctrl-f5时,它似乎可以满足他的要求。 I then made an exe and now it disappears, and it doesn't print to the console.
然后,我制作了一个exe,现在它消失了,并且不会打印到控制台。
I am using a simple cout program ex: 我正在使用一个简单的cout程序,例如:
int main()
{
cout<<"hello"<<endl;
return 1;
}
Edit I'm using visual studio 2013, and I am running from the command line. 编辑我正在使用Visual Studio 2013,并且正在从命令行运行。 Note I'm not asking for the window to stay open, but printing to the console itself.
请注意,我并不是要让窗口保持打开状态,而是要打印到控制台本身。 I am not pressing ctrl-f5, but going to cmd.exe and then to the executable.
我没有按ctrl-f5,而是先进入cmd.exe,然后再进入可执行文件。 I have tried the release version as well as the debug version.
我已经尝试了发行版以及调试版。
If I have understood your question. 如果我了解您的问题。 Try following and add useful parts to your code.
尝试按照以下说明向代码添加有用的部分。 Not needed lines are commented out.
不需要的行被注释掉。
// 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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.