Question:
What is the problem with my C++ compiler?
anonymous
2008-07-06 21:35:30 UTC
I'm C++ programming beginner. I've tried several C++ compilers and I really don't see what the problem is. I cannot still see "Hello world!" on my screen. I wrote the program as it is said in all the books and tutorials. At some compilers I was told I had errors which I couldn't understand and solve, at some the program was compiled successfully but after it became exe file it couldn't open. It would just show the black screen of command prompt for less than a second and disappear. I tried it both on my PC and laptop- the same thing! I can't understand what the problem is. It's the easiest program, the first program for every beginner (Hello world!). Could you please tell me what the problem is?
Three answers:
?
2008-07-06 21:49:16 UTC
The trick to keeping the screen up long enough to read is to have the program read something from the keyboard (cin or stdin) before the program terminates. Don't forget to press Enter when you're finished reading the output.



Hope that helps.
mr_bean
2008-07-07 04:49:47 UTC
Well, I can't magically guess what could be wrong with your computer without detailed system info, but I can diagnose the common problem of the command prompt flashing on, then off. In order for the words "Hello World" to stay up there, the program has to be manually told to stop and wait. The easiest way to do this is to insert the function "cin.get();" at the end of your "main()" function (I'm assuming the tutorials you are taking use the iostream header). This tells the computer to wait for the user to press enter before doing anything else. And perhaps your problems aren't actually from your computer, but rather the tutorials themselves. "cprogramming.com" offers some excellent tutorials for complete beginners. (However, previous experience in programming would be a real help.)
infoeager
2008-07-07 04:47:21 UTC
Don`t worry It`s a common mistake students make while writing program. from ur question i can tell you have not learned c yet...

Right...?

ok let`s solve the problem

1.add a line at startup of your program as



#include



i think you have already included stdio.h if not then again add

#include

2. now in your program just before exiting main function(before last "{" bracket) add following line



getch();



3.now run the program it will show output.



SECOND METHOD



after running your program in turbo c compiler press ctrl+f5

you will see output window.



former method is preffered.

and always use first method in every c or c++ program if you want to see complete output.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...