Hey guys i was reading the console closing down thing and in another topic(I made) someone recommended me to NOT use system("pause") thingy so i followed that step but i dont want to use cin.ignore() or the other one neither so i wanted to someone give me a small tool to terminate the console like system pause pressing a key but without IT.
#include <iostream>
#include <cstdlib>
#include <limits>
int halt(int, int);
int main() {
halt('a', 0);
return halt(0x1B, 0);
}
int halt(int key, int rtnVal) {
if (key == 0x1B) { // Escape key. If we are sent the escape key, we exit. Otherwise we try to find the enter key.
exit(rtnVal);
} else {
std::cout << "Press enter to continue...\n";
std::cin.ignore(std::numeric_limits <std::streamsize>::max(), '\n'); /* Ignore input until maximum amount of
characters read or enter pressed */
return rtnVal;
}
}
That would close the console if you wanted it to (by sending it the value of Escape, 0x1B or 1Bh (hex)). I just tested it and it works... so yeah.