console closing


// w.cpp : main project file.

This will compile but console closing too quick to see output. Yes I have used system(pause) and cin:get, etc, etc.What else without racking my beginner brain? Thanks, Deerking.

#include "stdafx.h"

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
cout << endl;
cout << "Hello again";
cout << endl;

return 0;
Instead of changing the code, just start the program from the console. (Under windows, shift-rightclick into the directory the exe is in, choose "open commandline here" (or something that sounds the like). Then you just type the name of the executeable.
Instead of changing the code, just start the program from the console.


That's a lot of work to do every time you want to run the program. Espeically when running from the IDE is as simple as pressing a single key.

Also it doesn't let you use the debugger.


As for the OP: there's no reason I can think of why cin.get() wouldn't work. It waits for user input, so the console should be staying open long enough to get that input.

Be sure you put cin.get() or whatever you use before your return 0 line, as "return 0" will exit the program.

That's a lot of work to do every time you want to run the program.

Not really. I personally have the console running all the time, cause it's just much more convenient.

And if the debugger runs through the program and just closes it without even asking you, I really have to wonder where the point in that thing would be.
closed account (D80DSL3A)
Try running with ctrl+F5. This is run without debug and the window stays open. No need for special code in the program for that.
Topic archived. No new replies allowed.