The function std::getline (already introduced with C++98) provides a portable way to implement this:
#include <iostream>
#include <string>
void press_any_key()
{
std::cout << "Press Enter to Continue";
std::string temp;
std::getline(std::cin, temp);
}
I found this thanks to this question and answer after I observed that std::cin <<>> temp;
does onlynot return with empty input. So I was wondering how to deal with optional user input (which makes sense for a string variable can of course be empty).