I have a text editor that uses the 'getch' function. I did this simply because 'std::cin' would not allow me to add spaces. I do have one problem now; although the loop is working perfectly, the 'backspace' button now prints a character to the console instead of erasing it! I was just going to find the ASCII code for the 'backspace' button, but I thought it would be much more useful to add functionality for the button instead of limiting its use. Here is the current program.
int main()
{
std::string filename;
std::string input;
char before;
std::cout << "Input the name of the file you want to create. ";
std::cin >> filename;
std::ofstream outfile(filename.c_str());
std::cout << "Input the data that you want to insert into this file." << std::endl;
while(before != '\r'){
before = getch();
std::cout << before;
input = input + before;
}
outfile << input;
outfile.close();
std::cout << std::endl << "Press the 'Enter' key to close the program.";
std::cin.ignore();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return 0;
}
You cannot get them using the standard input streams. You need to use specialized input methods.
I recommend you switch to Curses. It really isn't too steep a learning curve and you will have a lot more fun with it.