🔒 Locked
Dev-C++ iostream Problem
Advertisement
Original Post
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!
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.
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.
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.
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.
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
You should make it wait for a keypress, just add the line
cin.get ();
Im assuming I put that in the main function, but where? first line? Thanks btw.
Alright, added that line to the end of the function, before the return 0;
It works. Thanks everyone. I love you!
It works. Thanks everyone. I love you!
#include <conio.h>
getch();
getch();
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 ]
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
The topic is over guys... Someone else helped solve the problem, but thanks anyway.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement