Jump to content
  • Advertisement
Sign in to follow this  
JayDawg

DOS window problem

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
2 ways, one, run your program from the command prompt

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

should do it

Share this post


Link to post
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;
int adventurers, killed, survivors;
string leader;

//get the information
cout << "Welcome to Lost Fortune\n\n";
cout << "Please enter the following for your personalized adventure\n";

cout << "Enter a number: ";
cin >> adventurers;

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

survivors = adventurers - killed;

cout << "Enter your last name: ";
cin >> leader;

//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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

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



Standard pause.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!