0
void wait_enter(){
    cout <<"\nPress any key to continue...";
    char key;
    cin >> key;
};

I've written a function for my program like this in order to make a stop, because in my program i open up a text file and they need time to read, but whenever i hit the button enter it just goes to the next line, or leave a space and hit enter, that doesnt count as a char it seems,

how can i imply pressing enter to this function? getchar() - cin.get() or cin.ignore() doesnt seem to be working.

Evg
  • 25,259
  • 5
  • 41
  • 83
  • By default, reading from `std::cin` using the `>>` operator will *skip* spaces. And newline (what the `Enter` key produces) is a space. Read about [the `std::skipws` and `std::noskipws` IO manipulators](https://en.cppreference.com/w/cpp/io/manip/skipws) for *one* way to solve your problem. – Some programmer dude Nov 02 '21 at 07:28
  • I think getch() will do the job as it waits for the user to press any key to resume – Eatsam ul haq Nov 02 '21 at 07:28
  • 1
    @Eatsamulhaq `getch` is not a standard C++ function. – Some programmer dude Nov 02 '21 at 07:29

0 Answers0