Question: I am starting to write a command line converter and the only concern I have is user input (rest wont be hard). The program will have few commands like (convert 2 m to km), so when the user enters that, the program will output the converted value. My question is, what is the best way to parse user input and determine the command that user entered?. Should I divide user input into array of words and then pass to a function, so it can do something or there is another way?

Answer: 
I have written a few types of "simple parsers" (and several more advanced ones). From what you describe, if the commands are "convert 2 m to km", then you would simply need to split things on spaces. 

Of course, if you allow "convert2mtokm" and "convert 2m to km" it gets a bit more difficult to deal with. Sticking to a "strict rule of there has to be a(t least one) space between words" makes life a lot easier. 

At that point, you will have a `vector<string> cmd` that can be dealt with. So for example:

```
if (cmd[0] == "convert")
{
    convert(cmd); 
}

... 

void convert(vector<string> cmd)
{
    double dist = stod(cmd[1]);
    string unit_from = cmd[2]; 
    string unit_to = cmd[4]; 
    if(cmd[3] != "to")
    {
         ... print some error ... 
    }
    double factor = unit_conversion(unit_from, unit_to);
    cout << "that becomes " << dist * factor << " in " << unit_to << endl;
}

```
If you only have a few commands, it will be best to just `strtok(input, ' ')`, which just splits up a string into an array of words in the command (assuming your command words are all separated by spaces). Then you can do some simple if/switch checks to see which command the user entered. For a larger number of commands (where some may be similar), you will probably need to implement or at least write out a DFA (deterministic finite automata).