Hey guys, i've been using system("PAUSE") to halt the console and to see my output. But i've heard that it should not be used, so can anybody please tell me any other good alternatives so i can keep my console from closing instantly as soon as my program execution ends...
#include <iostream>
usingnamespace std;
bool run;
string choice;
void Pexit();
int main()
{
run = true;
while (run == true)
{
cout<<"/n What Do You Want To Do?"<<endl;
cout<<" Type /q To Quit"<<endl;
cin>>choice;
Pexit();
}
return 0;
}
void Pexit()
{
if(choice == "/Q" || choice == "/q")
run = false;
}
The program keeps looping, even if a wrong command is put in. I find this pretty simple and works for a lot of simple console programs. Not sure what the community think of this, i have never used getch to be honest...
EDIT: When you do /q using this, it says 'Press another key to end' or whatever...
Do you know of GCC (often referred to as g++ by C++ coders)? That doesn't come with a conio.h implementation, and it's one of the world's most widely used compilers.
Then when you want to pause your program you just put pause();. Added bonus, if you happen to be including cstdlib for other things like "system()", "srand()" and "rand()" then use "atexit()" to make sure your application is held open at the very end. http://www.cplusplus.com/reference/clibrary/cstdlib/atexit/