Skip to content

Instantly share code, notes, and snippets.

@NickersF
Created November 25, 2015 06:59
Show Gist options
  • Save NickersF/2e094fbb87b4b774fa73 to your computer and use it in GitHub Desktop.
Save NickersF/2e094fbb87b4b774fa73 to your computer and use it in GitHub Desktop.
C++ - Generic function which closes a win32 console application
// A generic function to close win32 console applications
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void closeApp();
int main() {
closeApp();
return 0;
}
// application termination function
void closeApp() {
// local variables
bool inputSafe = false;
string reply;
string accept = "q";
while (!inputSafe == true) {
cout << "Please enter q to exit the application: ";
cin.clear();
getline(cin, reply);
if (reply == accept) {
inputSafe = true;
exit(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment