As mentioned by others, the problem is that while reading the command you are leaving the end of line character in the buffer. Besides the alternative proposed by @Armen Tsirunyan, you can use two other approaches:
Use std::istream::ignore
for that: cin.ignore( 1024, '\n' );
(assuming that lines will not be greater than 1024 characters in width.
Just replace cin >> command
with getline( cin, command )
.
Neither alternative requires creating an extra string, the first is weaker (in the event of very long lines), the second alternative modifies the semantics, as now the whole first line (not just the first word) is processed as the command, but this might be fine as it allows you to perform tighter input checking (the command is spelled as required in the first word, and there are no extra options in the command line.
If you have different set of commands and some might need an argument, you can read the command line in one pass, and then read the command and arguments from there:
std::string commandline;
std::vector<std::string> parsed_command;
getline( cin, commandline );
std::istringstream cmdin( commandline );
std::copy( std::istream_iterator<std::string>(cmdin), std::istream_iterator(),
std::back_inserter( parsed_command ) );
// Here parsed_command is a vector of word tokens from the first line:
// parsed_command[0] is the command, parsed_command[1] ... are the arguments