I have been told to make an exe file that will output 5 lines. 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. I then made an exe and now it disappears, and it doesn't print to the console.
I am using a simple cout program ex:
int main()
{
cout<<"hello"<<endl;
return 1;
}
Edit I'm using visual studio 2013, and I am running from the command line. 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. 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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.