Senior Member
Posts: 606
Threads: 67
Joined: 2010-11
So I was trying out a hello world program. The code is as follows:
// A Hello World program
#include <iostream>
int main() {
std::cout << "Hello, world!\n";
return 0;
}
After debugging, basically shows hello world on a command print for the briefest of seconds and then vanishes. What's up with that? When I was using c# the command prompt window would stay open until I exited it. Is there a way to keep the hello world window open longer?
Posting Freak
Posts: 1,052
Threads: 15
Joined: 2009-09
Either run it directly from cmd or there should be a setting in whatever IDE you're using to prevent the window from being closed right away.
Senior Member
Posts: 606
Threads: 67
Joined: 2010-11
I'm using Microsoft visual c++. Do you know where the relevant buttons might be found?
Posting Freak
Posts: 854
Threads: 71
Joined: 2008-07
Gender: Male
Sexual Orientation: Straight
Country Flag: usa
Job: Software Dev.
Or you could put a breakpoint on return 0.
Member
Posts: 136
Threads: 0
Joined: 2011-06
Gender: Male
Sexual Orientation: Straight
Country Flag: peru
IGN: iatLnbandLt
Server: Broa
Level: 170
Job: Shadower
Guild: ForgeKeepers
For visual C++ if you want for the command prompt to stay then you need to add keep_window_open()
ie:
int main() {
//your code
keep_window_open();
return 0;
}
Posting Freak
Posts: 4,171
Threads: 58
Joined: 2010-09
Gender: Male
Sexual Orientation: Bi
Country Flag: venezuela
IGN: xxxxFenixR
Server: Bera
Level: Mix
Job: Severals
Guild: None
Guild Alliance: Nada
Farm: Wut?
mmm System Pause or something along those lines? I forgot, not practicing my coding religiously takes a dent on me (Especially since the last time i touched C++ was a year ago)
Posting Freak
Posts: 3,586
Threads: 232
Joined: 2008-07
Gender: Male
Sexual Orientation: Gay
Country Flag: canada
IGN: Jed
Level: 21
Job: Engineer
Guild: ACNL
Farm: West Egg
Ooh, this has been bugging me too.
In labs for school, I wasn't allowed to read extra input to act as a "Press ENTER to exit" thing, so I ended up just running it in my own IDE where it works fine (for the record, I use Eclipse).
Member
Posts: 136
Threads: 0
Joined: 2011-06
Gender: Male
Sexual Orientation: Straight
Country Flag: peru
IGN: iatLnbandLt
Server: Broa
Level: 170
Job: Shadower
Guild: ForgeKeepers
Do NOT use system("pause"), using system("whatever") is in most cases the mark of the noob coder. Just saying.
Alternatively to keep_window_open(), you can create your own keep_window_open() by doing this:
int main() {
//your code
string quit="";
while(quit!="quit") cin>>quit; //wait until "quit" is written and entered before exiting.
}
Posting Freak
Posts: 1,052
Threads: 15
Joined: 2009-09
In Visual Studio, you right click on the project, select properties, go to configuration properties, linker, system, make sure the property SubSystem is CONSOLE (/SUBSYSTEM:CONSOLE).
This should work for when you run without debugging.
If you are debugging then you should have break points set anyway.