• Welcome to Dark Bit Factory & Gravity.
 

[C++] First Program

Started by a4r9, June 14, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

a4r9

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();
}

Pixel_Outlaw

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.
Challenge Trophies Won:

mziskandar

Works fine with CodeBlocks (mingw) too..

ferris

try replacing "cin.get();" with "System("PAUSE")"
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Jim

In general, there's no way to make it pause.  system("pause") will only work on PCs.

Welcome to the forum a4r9!

Jim
Challenge Trophies Won:

Rbz

Try to make a loop with do..while and check when user press enter for example.
Challenge Trophies Won:

Hotshot

Welcome to the forum a4r9!

Welldone on your first c++ program and keep going  ;) :)

a4r9

Thanks ya'll, although it's still not working, still doing the same thing, I'm starting to think it's the OS

Hotshot

What is doing the same things?
What error did you have?
what OS do you have?

a4r9

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.

Hotshot

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;
}

a4r9

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

Hotshot

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 :)

madsravn

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

a4r9

Indeed it works in XP, it must be the operating system then.

Clyde

Congrats dude on getting it fixed.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Pixel_Outlaw


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.
Challenge Trophies Won:

ferris

I learned all I know of C++ from Preacher/Traction's source code and the OpenGL API from http://nehe.gamedev.net/, though GLSL I learned from the Orange Book.
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won: