Hey guys...

I have Borland C++ compiler with version 5.02.
The problem is that once I run the code, it makes and just flashes and disappears.
I mean, in a simple 'hello world program', the program just cout 'hello world' and closes itself.
I tried getch(); and it did work, but however I want it to stay open without any commands.
In my school, we have borland 4.98 in which we could type in the code and run it, and it just stays open until we close the window.
The hello world code is :

#include<iostream.h>
int main()
{
    cout<<"Hello world!";
}

I have run it on my school computer (with borland v.4.98) and it stayed open without closing, but on my computer at home (with borland v.5.02), the program just flashes "Hello world" and closes itself...

Can you guys recommend what could be probably wrong with my computer, are there some special setting to borland which could enable them to stay on after the code is completed?
I want something permanent, unlike getch(); which i have to add after every code end...

Thank You!!

Recommended Answers

All 3 Replies

After the cout (and add an << endl to the line), you need to pause the problem. Usually this is done by taking some input, such as a line like char avar; cin >> avar;. That should keep the window open until you hit the Enter key.

Can you guys recommend what could be probably wrong with my computer

There is nothing wrong with your computer. This is what is meant to happen. You ask it to run a program, it opens a window to run the program, when the program is finished the window closes.

Some IDEs come with an option somewhere to hold the window open when the program has finished. If the previous version of Borland did, maybe your one does too.

Alternatively, open a window yourself and run your program from the command line.

Such happening when run not under console.
Just add at end of your program:

#include<iostream.h>
int main()
{
    cout<<"Hello world!";
    system("pause");
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.