Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: a4r9 on June 14, 2009

Title: [C++] First Program
Post 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.

Code: [Select]
#include <iostream>
      
using namespace std;
      
int main()
{
 cout << "Hello World!" << endl;
          
 cin.get();
}
Title: Re: [C++] First Program
Post by: Pixel_Outlaw on June 14, 2009
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.
Title: Re: [C++] First Program
Post by: mziskandar on June 14, 2009
Works fine with CodeBlocks (mingw) too..
Title: Re: [C++] First Program
Post by: ferris on June 14, 2009
try replacing "cin.get();" with "System("PAUSE")"
Title: Re: [C++] First Program
Post by: Jim on June 14, 2009
In general, there's no way to make it pause.  system("pause") will only work on PCs.

Welcome to the forum a4r9!

Jim
Title: Re: [C++] First Program
Post by: Rbz on June 14, 2009
Try to make a loop with do..while and check when user press enter for example.
Title: Re: [C++] First Program
Post by: Hotshot on June 14, 2009
Welcome to the forum a4r9!

Welldone on your first c++ program and keep going  ;) :)
Title: Re: [C++] First Program
Post by: a4r9 on June 14, 2009
Thanks ya'll, although it's still not working, still doing the same thing, I'm starting to think it's the OS
Title: Re: [C++] First Program
Post by: Hotshot on June 14, 2009
What is doing the same things?
What error did you have?
what OS do you have?
Title: Re: [C++] First Program
Post by: a4r9 on June 14, 2009
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.
Title: Re: [C++] First Program
Post by: Hotshot on June 14, 2009
Strange.

try that as work very well with Visual C++ 2008 Express!

Code: [Select]
# 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;
}
Title: Re: [C++] First Program
Post by: a4r9 on June 14, 2009
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
Title: Re: [C++] First Program
Post by: Hotshot on June 14, 2009
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 :)
Title: Re: [C++] First Program
Post by: madsravn on June 18, 2009
Sometimes cin.get() takes something from buffer (or something), I think I heard.

Try doing a cin.get(ch).get(ch);
Code: [Select]
#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
Title: Re: [C++] First Program
Post by: a4r9 on June 22, 2009
Indeed it works in XP, it must be the operating system then.
Title: Re: [C++] First Program
Post by: Clyde on June 22, 2009
Congrats dude on getting it fixed.
Title: Re: [C++] First Program
Post by: Pixel_Outlaw on June 23, 2009

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.
Title: Re: [C++] First Program
Post by: ferris on June 23, 2009
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.