Getting a single, immediate character from the user is a platform-specific kind of thing to do. There are libraries that help minimize multi-platform problems (like NCurses), but for something simple you might as well just use the proper platform-specific code.
friend, I'm newbie . . . give me simple Idea for solve this problem,
I just want, when user press esc/27 the program back to the main menu
if I using getch() for this case, that mean I can't ask input for the file name will be open,
open file : _
user can input file name, but when user press esc , program will go to main menu,
A simple idea would be to use cin to get the file name, and enable the user to cancel the operation by entering '*' and hitting enter. '*' can't be part of the name of a file, so it's ok.
cout << "Please enter a filename to open (or only press enter to cancel)\n> " << flush;
getline( cin, filename );
if (filename.empty())
{
cout << "Cancelled.\n";
return;
}
ifstream f( filename.c_str() );
...
and you regret it in the middle of typing, you'll have to hold backspace for a while until you erase all of that. I believe it would be much simpler to check if the last character entered is a '*'.
Of course, you may also add the option to check for an empty string just in case the user immediately hits enter.