Archived

This topic is now archived and is closed to further replies.

Dev-C++ iostream Problem

This topic is 5675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ();


Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites