Advertisement

Compiler

Started by February 11, 2003 09:58 PM
4 comments, last by Name-ing-Way 21 years, 9 months ago
Hello. I had Borland C++ v4.52, and it was giving me problems. Even on the most simple of programs, ie: #include <iostream.h> int main() { cout << "hello"; return(0); } it would not work. It would give me a general protection expception error. So, I obtained Borland v5. Now I don''t get a general protection fault, now it runs the program and the run disappears immediately. Does anyone know what I have to do to get this compiler working? It would be a great help. On a final note, I''ve had Borland 4.52 working on my computer in the past, and all of a sudden it just stopped working. Since then I have wiped my whole computer clean and reinstalled windows (not because of Borland). And right after this, Borland still wasn''t working.
I''m abou 99.9% certain I know what''s wrong.

In this case, it has absolutely nothing to do with borland, it''s because of the way Windows treats console programs(what you made). When the program is done running, windows automatically closes it. Ouch! There are many ways around it. I''ll offer one and I''m sure others will offer more.
cout << "hello" <<;int temp;cout << "--->Type any number(it doesn''t matter) and hit enter to exit: ";cin >> temp;return(0); 


the cin statment halts further program execution, effectively pausing the program. Just type a short number and hit enter to leave.
Advertisement
dangit, the code above should be this:

cout << "hello"; // no <<, the program won''t compile
int temp;
cout << "--->Type any number(it doesn''t matter) and hit enter to exit: ";
cin >> temp;
return(0);
Actually, I had just figured that out before I read your post. With the older version of Borland I had, (v4.52), it left the window open after the run of the program. With this new version (v5), it closes the window =(. So, waiting for user input IS one option, which I may end up having to do, but, if there is a way to set it so it behaves like Borland 4.52 I would be very grateful. Thanks for your help btw.
quote: Original post by Name-ing-Way
Actually, I had just figured that out before I read your post. With the older version of Borland I had, (v4.52), it left the window open after the run of the program. With this new version (v5), it closes the window =(. So, waiting for user input IS one option, which I may end up having to do, but, if there is a way to set it so it behaves like Borland 4.52 I would be very grateful. Thanks for your help btw.


Depending on why you need a console window, you can explicitely create a console (NOT a DOS-Box, but a console window), which will remain open until a) your app exits, b) your app closes the console window.

If you are just trying to compile DOS-Box type programs, you don''t have much choice but to "Press a key to close window...". Of course, that could get annoying if you run it from DOS or a DOS-box which won''t close on exit anyhow..

Another option is to hide the actual invocation of the app behind a shortcut with appropriate settings to keep the window open. The end user will still have to close the window manually anyhow, so it''s just a "press any key" variant along the lines of "Press any [X] in the corner"
instead of creating a variable and requiring that it be an integer, etc. you could just use getch()

cout << "hello";
getch();

return 0;

This topic is closed to new replies.

Advertisement