Hello,
I'm implementing a little command line parser. Let's say I have a command that requires 2 parameters. I want to let the user type all 3 strings (the command and 2 parameters) on one line, as well as on several lines. Currently I'm having something like this:
std::string command;
std::cin >> command;
std::cout << command << " entered\n";
std::string param1;
std::cin >> param1;
std::cout << param1 << " entered\n";
std::string param2;
std::cin >> param2;
std::cout << param2 << " entered\n";
Now I want to be able to detect that the user has just entered the command without any parameter, and output directions for that. I think after getting the command I should test if the line contains anything else and if it doesn't, ask the user to type more. I have tried with eof()
and fail()
but they do not work. How can I check for that then?
Thanks.