[SOLVED] Console application question
Moderator: Coders of Rage
- Kyosaur
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Tue Jul 13, 2010 2:00 am
- Favorite Gaming Platforms: PS2,PS3,NDS
- Programming Language of Choice: C++
[SOLVED] Console application question
I decided to take up c++ and make a simple console game. Im just wondering if there is a way to stop the console from closing until i call a certain function (maybe OnGameModeEnd) ? I know of system("pause"); but its not exactly what im looking for.
Last edited by Kyosaur on Sun Jul 18, 2010 2:29 am, edited 3 times in total.
Re: Console application question
Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h>
void main()
{
bool exit=false;
while(!exit)
{
if(kbhit())
if(getch()=='q')
exit=true;
}
}
- Kyosaur
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Tue Jul 13, 2010 2:00 am
- Favorite Gaming Platforms: PS2,PS3,NDS
- Programming Language of Choice: C++
Re: Console application question
Ohh nice, thanks.zeid wrote:Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h> void main() { bool exit=false; while(!exit) { if(kbhit()) if(getch()=='q') exit=true; } }
EDIT: Is there a way to make it accept input? Kind of hard to make a text based game if you cant input anything D:.
-
- Chaos Rift Regular
- Posts: 173
- Joined: Thu Feb 11, 2010 9:46 pm
Re: Console application question
The example zeid posted does take in input. All you have to do is store it in a string. You might want to use std::cin though, it's standard C++.Kyosaur wrote:Ohh nice, thanks.zeid wrote:Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h> void main() { bool exit=false; while(!exit) { if(kbhit()) if(getch()=='q') exit=true; } }
EDIT: Is there a way to make it accept input? Kind of hard to make a text based game if you cant input anything D:.
Code: Select all
std::string input;
std::cout << "Enter your name.\n";
std::cin >> input;
std::cout << "Your name is: " << input << ".\n";
- Kyosaur
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Tue Jul 13, 2010 2:00 am
- Favorite Gaming Platforms: PS2,PS3,NDS
- Programming Language of Choice: C++
Re: Console application question
Thanks, thats exactly what i was looking for :D.X Abstract X wrote:The example zeid posted does take in input. All you have to do is store it in a string. You might want to use std::cin though, it's standard C++.Kyosaur wrote:Ohh nice, thanks.zeid wrote:Here is a simple solution. The program is sequential so what we do is return to the start of the program so long as the conditions to exit haven't been met.
Code: Select all
#include<conio.h> void main() { bool exit=false; while(!exit) { if(kbhit()) if(getch()=='q') exit=true; } }
EDIT: Is there a way to make it accept input? Kind of hard to make a text based game if you cant input anything D:.
Code: Select all
std::string input; std::cout << "Enter your name.\n"; std::cin >> input; std::cout << "Your name is: " << input << ".\n";
Sorry for the n00by question lol, im still learning .
-
- Chaos Rift Regular
- Posts: 173
- Joined: Thu Feb 11, 2010 9:46 pm
Re: Console application question
Everyone's been there, don't be afraid to ask anything.
- Kyosaur
- Chaos Rift Cool Newbie
- Posts: 78
- Joined: Tue Jul 13, 2010 2:00 am
- Favorite Gaming Platforms: PS2,PS3,NDS
- Programming Language of Choice: C++
Re: Console application question
ok lol.X Abstract X wrote:Everyone's been there, don't be afraid to ask anything.
going to add solved to the tittle now, thanks again for the help guys :D.