hello. am a new student to programming! am doing c in my computer science class at university, as dev cpp as the compiler; - but am disappointed each time I try to run a program. the program just flashes off the screen! am using windows 7 professional s a platform. what should i do about it? thanx.

6 Years
Discussion Span
Last Post by collinskawere

This is a common problem with IDEs that don't artificially keep the window open for you. The actual problem is that the IDE creates a window to host your program, and when the program ends the window is destroyed. The solution is to force your program to continue running by blocking for input at the end:

#include <iostream>

int main()
    std::cout << "Hello, world!\n";
    // Block for input to keep from terminating

This solution can be a problem if your standard input stream isn't empty at the time you try to block, so for that case you need to clear the stream first as described in this tutorial.

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.