How do I make cout stay on the screen?
Currently I am learning C++ and I have learned about cout but once the program is compiled it flashes and goes back to my compiler without showing the text. I''m using DevC++. Is there an adjustment in Dev I can use to change it so it will stay on the screen.
~BSGamePlaya~
~BSGamePlaya~
Actually, that happens with all of devC++ programs. I don''t know if there are any adjustments you can make, but if you go find the executable in the folder where you compiled it to, it wont do that. Additionally, you can add getchar() function with It simply stops the program until it reads in a key.
If you mean that if executes and the ends try this:
#include <stdlib.h>
int main()
{
. . . //your program code
cout << endl;
sytstem("PAUSE");
return 0;
}
#include <stdlib.h>
int main()
{
. . . //your program code
cout << endl;
sytstem("PAUSE");
return 0;
}
You could open up a DOS prompt (or Command Prompt, or whatever Windows calls it now), find the directory the executable is in and run it by typing its name.
The DOS box wont close after the program has run
Wizzard
The DOS box wont close after the program has run
Wizzard
#include <iostream.h>#include <conio.h> // for the getch()-functionvoid main(){ cout << "Hello World!" << endl; getch();}
That should do it. getch() waits until you press any key and then it returns to VC++ or whatever you're using to execute the code. Now you just have to find that "any-key"
edit - messed up the code-tags
[edited by - Rickmeister on March 15, 2002 11:20:19 AM]
quote: Original post by BSGamePlaya
Currently I am learning C++ and I have learned about cout but once the program is compiled it flashes and goes back to my compiler without showing the text. I''m using DevC++. Is there an adjustment in Dev I can use to change it so it will stay on the screen.
~BSGamePlaya~
I don''t know if this is good programming or bad - but its one way to do it.
#include <stdio.h>#include <iostream>int main(){ std::cout << "Hello." << endl; getchar(); return 0;}
Hello from my world
quote: Original post by Rickmeister#include <iostream.h>...
actually, you should use #include iostream, not #include iostream.h ...I think that works on DevC++, I've never used it...
quote: Original post by flame_warrior#include <iostream>int main(){ std::cout << "Hello." << endl;getchar();
The one problem with this is that you have to use std namespace. Instead of using std::cout and std::cin and std::everythingElse, you can just put
using namespace std;
right below the #include, and it will automatically assume that anything thats not global is std namespace (or is it that anything thats not std namespace is global...?)EDIT: the word iostream wasn't appearing when I put it in greater/less-than brackets
"I've learned something today: It doesn't matter if you're white, or if you're black...the only color that really matters is green"
-Peter Griffin
[edited by - matrix2113 on March 15, 2002 7:00:33 PM]
"I've learned something today: It doesn't matter if you're white, or if you're black...the only color that really matters is green"-Peter Griffin
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement