Reputation: 113
For example, any character different than a b c..x y z
or A B C..X Y Z
or -
needs to be seperated and put in a vector.
How can I achieve this ?
std::string inputLine;
vector<string> inputs;
getline(std::cin, inputLine);
at this point I got the string from the user input, how can I split it ?
For example: hello,sir my nameéis ada-m should be put in a vector as follows
inputs.at(0): hello
inputs.at(1): sir
inputs.at(2): my
inputs.at(3): name
inputs.at(4): is
inputs.at(5): ada-m
Upvotes: 0
Views: 417
Reputation: 16448
This is an simple algorithm
inputs
s
c
of your input string inputLine
c
in 'a' 'b' 'c'..'x' 'y' 'z'
or 'A' 'B' 'C'..'X' 'Y' 'Z'
or '-'
c
to s
s
to inputs
(you could also check if s
is empty)s
s
to inputs
(you could also check if s
is empty)Upvotes: 1