Dark Bit Factory & Gravity
PROGRAMMING => C / C++ /C# => Topic started by: a4r9 on June 14, 2009
-
Hello, this is my first C++ program. It should be pausing but does not pause. Instead it simply creates the window displaying the message and then quits. How can I make the window stay open to read the message? I'm using Dev-C++ under Windows 2k.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cin.get();
}
-
I'm fairly new to C++ myself and your code works fine. I'm not quite sure what the problem is with your computer. I'm using Dev-C++ myself but running it in XP.
-
Works fine with CodeBlocks (mingw) too..
-
try replacing "cin.get();" with "System("PAUSE")"
-
In general, there's no way to make it pause. system("pause") will only work on PCs.
Welcome to the forum a4r9!
Jim
-
Try to make a loop with do..while and check when user press enter for example.
-
Welcome to the forum a4r9!
Welldone on your first c++ program and keep going ;) :)
-
Thanks ya'll, although it's still not working, still doing the same thing, I'm starting to think it's the OS
-
What is doing the same things?
What error did you have?
what OS do you have?
-
Is still coming up with a screen then going away instantly either saying already compiling or source could not compile. And I have Windows 2000 sadly.
-
Strange.
try that as work very well with Visual C++ 2008 Express!
# include <iostream>
using namespace std;
int main()
{
cout <<"hello world";
// Pause the Screen
getchar(); // This line of code is from Programming C but still pause the screen and it is work!
return 0;
}
-
That still doesn't work, I'm starting to think that maybe I should try it on my mom's computer, she runs XP, I miss it, was great for everything XD
-
The program I have used above on DEV C++(I have check that) and Visual C++ 2008 Express work very well on either XP and Vista too but not sure about Window 2000 thought. :)
let me know how you get on thought when you go on XP testing your program :)
-
Sometimes cin.get() takes something from buffer (or something), I think I heard.
Try doing a cin.get(ch).get(ch);
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
char ch;
cin.get(ch).get(ch);
return 0;
}
I know it isn't pretty, but it should work. You would maybe be able to do cin.get().get(). I thought I could too, but g++ started whining about it.
/ Mads
-
Indeed it works in XP, it must be the operating system then.
-
Congrats dude on getting it fixed.
-
Yes, I don't have any idea why it would not work on you other OS...
If you want a game based C++ book you might try C++ Programming for the Absolute Beginner just ignore the last chapter on DirectX as we all know it is one of the tendrils of the Microsoftoctopus. C++ for Dummies is also very extensive. After finishing Beginning C++ Game Programming I can honestly say that the later chapters of the book completely fall apart. The author stops commenting on code and starts introducing like 2 new concepts each exercise.
-
I learned all I know of C++ from Preacher/Traction's source code and the OpenGL API from http://nehe.gamedev.net/ (http://nehe.gamedev.net/), though GLSL I learned from the Orange Book.