Run window query

Dec 30, 2009 at 12:56am
I have been testing my compiler (Bloodshed) by inserting simple programs (cout), and I find that the run window closes too quickly for me to view the results. I am not very familiar with compilers, and I was wondering if there was any way I could remedy this. Is there some setting that I can choose so I can manually close the run window, or is this issue arising from the brevity of the code itself?

Thank you.
Dec 30, 2009 at 1:12am
Dec 30, 2009 at 1:29am
Greetings.

I have looked through that thread before, and for some reason none of the suggestions are working. Might there be something wrong about my compiler?
Dec 30, 2009 at 1:49am
Most if not all of those should work with that particular compiler. You must be doing it wrong.
Dec 30, 2009 at 2:03am
Hello Helios,

Thank you for the advice, I am very new to C++ and am probably missing something without knowing it.

Would you mind supplying me a very simple example that would and should work?
Dec 30, 2009 at 2:10am
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main(void)
{
	cin.ignore();
	return(0);
}
Dec 30, 2009 at 2:19am
The simplest one, but which I personally don't recommend, is
1
2
3
4
5
6
#include <cstdlib>

int main(){
    //...
    system("pause");
}


A better one is
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <climits>

struct Stop{
    ~Stop(){
        std::cout <<"Press enter to continue"<<std::endl;
        std::cin.ignore(INT_MAX,'\n');
        std::cin.get();
    }
} stop_at_end;

//... 
You may notice that you have to press enter twice if there was no input.

But my favorite is to not use any of this and to just run the program from the console, as it was meant to be.
Dec 30, 2009 at 1:06pm
Thank you! It works now.
Topic archived. No new replies allowed.