Typing "exit" to exit program

Mar 3, 2009 at 11:40pm
Good evening everyone! I'm new to both C++ and the forums but have searched everywhere and have not found what i have needed.
I need help setting up code so that whenever I(or anyone else) types in "exit" to exit the program. Any help is appreciated.
Note: this is only for debugging purposes NOT for any real program.
Mar 4, 2009 at 12:53am
What does your code look like for getting user input? It's hard to tell you how to proceed without knowing where you started.
Mar 4, 2009 at 1:00am
Here it is:
1
2
3
4
5
6
7
8
int main()
{
	...
	cin >> SHOOT;
	cout << " Press Enter to continue...";
	cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
	...
}
Mar 4, 2009 at 1:11am
What type of variable is SHOOT?
Mar 4, 2009 at 1:16am
it's a string variable. -EDIT-I believe I have something that will work for debugging and laziness purposes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <limits>
#include <string>
using namespace std;



int main()
{
	int exit = 0;
	
	while ( exit < 1 )
	{
		cin >> exit;
	}
	return 1;
}  
unless you can give me a more efficient/better way(which i'm sure you do =) ).
Last edited on Mar 4, 2009 at 1:23am
Mar 4, 2009 at 1:25am
if(SHOOT == "exit")
return 0;
Mar 4, 2009 at 1:40am
thanks. =)
Topic archived. No new replies allowed.