Skip to main content
gamedev.net
🔒 Locked

Dev-C++ iostream Problem

Started by IconoKlast 10 replies 500+ views
Original Post
IconoKlast
IconoKlast
Well, Ive got a problem, when I type a program, simple or otherwise, Dev-C++ doesn''t want to run it. It compiles A-ok but, when I press the ''run'' button, a DOS screen flashes up and then goes away, and I cant even tell it my cout is even displayed... Someone help please, my good programming buddy said it was something that Windows stopped putting in its OSs that C++ needs to run. Can anyone confirm this? Any help is appreciated. Sample text... #include <iostream> using namespace std; int main() { int length; //this declares a variable length = 7; // this assigns 7 to length cout << "The length is "; cout << length; //this displays 7 return 0; } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This does not work for me, the same dang flashing screen... Help!
-=Kids Love It!=-
Pegu
Pegu
Have you tried other compilers ?
They should give the same result.

Because the program will just print number 7 on the screen, and then quit. If you make the program to wait for a keypress after it has printed the number, you should be able to see it.

Or... you can go to MS-DOS prompt and run your program from there.
Pegu
Pegu
And I think that you should ask your friend more about that ''fact''...
IconoKlast
IconoKlast
Alright, good idea on the alternate compilers suggestion... I believe I used Borland to do the same operation when I was just learning and it created errors, but eventually did the same terminating operation problem.

But about the keystroke-termination idea, I guess that''d work, but my point is that its such a simple operation... and also, if anyone else has Dev-C++ help me out here, but shouldnt there be a place in the compiler program that shows you the output? Sorry if this is all naive, heh.
-=Kids Love It!=-
Kippesoep
Kippesoep
It probably works just fine. When your program runs, it displays a console (what some people call a "DOS window") and after if finishes, the console is closed. This happens so fast that you don''t see what''s going on.

You should make it wait for a keypress, just add the line

  
cin.get ();


Kippesoep
IconoKlast
IconoKlast
Im assuming I put that in the main function, but where? first line? Thanks btw.
-=Kids Love It!=-
IconoKlast
IconoKlast
Alright, added that line to the end of the function, before the return 0;

It works. Thanks everyone. I love you!
-=Kids Love It!=-
Pegu
Pegu
quote:
Original post by IconoKlast
Im assuming I put that in the main function, but where? first line? Thanks btw.


Hrrrm... the line before "return 0"

Btw, the compiler suggestion was a joke. The thing that happens to you is not a bug, or error...
penguin
penguin
That is one of the problems that bug newbies that use Dev-C++...
Put

int tempo=0; scanf("...",tempo);

before return 0; and you should be just fine...

(got this off cone3d)
Fruny
Fruny
This is perfectly normal behavior : as the program terminates, the console window is closed. Open a console window yourself ("dos prompt"), then run your program in there.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
IconoKlast
IconoKlast
The topic is over guys... Someone else helped solve the problem, but thanks anyway.
-=Kids Love It!=-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.