I have really hard time to get this. If my input is empty, I mean "Enter button" (means empty string, whitespaces), how can I detect it using C++?.
using namespace std;
If you want an empty input to be accepted you have to tell the input stream to not skip whitespace using the
noskipws IO manipulator:
cin >> noskipws >> a;
Your code should then work as you want it to.