Public Group

# DOS window problem

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, First time posting, and I know this is a really dumb problem, but I just started learning C++ with the Beginning C++ Game Programming book by Michael Dawson. Anyways, my problem is getting the DOS window that pops up to stay on screen (the one that comes up when you run your little program after compiling). The book provides a bit of code you can use so you have to press enter to exit, but that only works some of the time, and I know there is a setting in windows or something that allows the DOS window to remain open until you terminate it, I just cannot find it. I am on WinXP Pro SP2, using Bloodshed DevC++, thanks a load for the help!!!

##### Share on other sites
2 ways, one, run your program from the command prompt

two, add getch(); just before return 0; at the end of main().
#include <stdlib.h>

should do it

##### Share on other sites
Thanks for the help. The command prompt method works just fine, but putting #include <stdlib.h> with the other #includes at the top, and adding getch(); generates an error on the getch(); line. Here is a copy of the code, it's one of the examples in the book (and I added what you mentioned).

#include <iostream>
#include <string>
#include <stdlib.h>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
const int GOLD_PIECES = 900;

//get the information
cout << "Welcome to Lost Fortune\n\n";

cout << "Enter a number: ";

cout << "Enter a number, smaller than the first: ";
cin >> killed;

cout << "Enter your last name: ";

//tell the story
cout << "\nA brave group of " << adventurers << " set out on a quest ";
cout << "-- in search of the lost treasure of the Ancient Dwarves. ";
cout << "The group was led by that legendary rogue, " << leader << ".\n";

cout << "\nAlong the way, a band of marauding ogres ambushed the party. ";
cout << "All fought bravely under the command of " << leader;
cout << ", and the ogres were defeated, but at a cost. ";
cout << "Of the adventurers, " << killed << " were vanquished, ";
cout << "leaving just " << survivors << " in the group.\n";

cout << "\nThe party was about to give up all hope. ";
cout << "But while laying the deceased to rest, ";
cout << "they stumbled upon the buried fortune. ";
cout << "So the adventurers split " << GOLD_PIECES << " gold pieces.";
cout << leader << " held on to the extra " << (GOLD_PIECES % survivors);
cout << " pieces to keep things fair of course.\n";

getch();
return 0;
}

Thanks so much again!

##### Share on other sites
Try #include <cstdlib> instead of <stdlib.h>
I think stdlib.h is deprecated!? Not sure if that helps, though.

##### Share on other sites
Gave it a go... gives the exact same error on the line with getch(); So I have no darn clue what to do :| Sucks to try and learn something but you can't see the results really you know? Even if it's dinky stuff like this, still is nice to be able to view it!! Thanks for the try, and if anyone else knows anything, please help!

##### Share on other sites
getch() is in conio.h. But it isn't part of the standard, so it's not sure you can use it; it depends on what compiler you are using.

##### Share on other sites
use cin.get(); it is standard, as it is part of std::cin

##### Share on other sites
Hmmm... How am I to apply use of cin.get();? It doesn't give me an error or anything if i add it just before return 0; (remember, i'm a brand new beginnner here, so if there's anything assumed by you guys, I probably wont know it), but however it does not fix the issue, the window still closes. I am using Bloodshed Dev C++ 4.9.8.0 to compile and run. Thanks alot for the speedy replies and your time.

UPDATE:
I tried the #include <conio.h> along with getch() and it worked perfectly! Thanks a bunch, I am releived to finally get this issue fixed. I would however still like to know about the cin.get(); and how I might get that one to work, if anyone has a chance.

##### Share on other sites
void my_pause(){    cout<<"Press [ENTER] to continue."<<endl;    cin.get();}int main(){    my_pause();    return 0;}

Standard pause.

##### Share on other sites
//your code goes below...system("PAUSE");...

1. 1
2. 2
JoeJ
20
3. 3
frob
20
4. 4
5. 5

• 10
• 11
• 12
• 13
• 9
• ### Forum Statistics

• Total Topics
632211
• Total Posts
3004818

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!