0

ok im new so i dont really know what im doing but when i put the example program in dev and compile it everything works fine but when i run it it still works fine but the black screen what shows you the result of thr program lasts like 1 second
#include <iostream.h>

int main ()
{
       cout << "hi world \n";
       return 0;
}

the result lasts less than a second how do i fix this

Edited by Narue: Added code tags

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Moschops
0

Clearly you didn't search the forums before asking this question, because it's very common. You need to add a pause at the end of the program because the IDE allocates a console window for it to run. When the program ends, the window is destroyed and closes. The Dev-C++ code examples (which you also clearly didn't read) use the system function:

#include <iostream.h>
#include <stdlib.h>

int main()
{
    cout << "hi world\n";
    system("PAUSE");
    return 0;
}

Though that's not a recommended practice, it'll suffice until you're ready to tackle the not so trivial issues involved in better solutions.

0

When you get that sorted out, don't forget to please stop using Dev-C++ and move to something far, far better. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.