Having the following type of input:
add name, breed, birthDate, vaccinationsCount, photograph
(e.g. add boo, yorkshire terrier, 01-13-2017, 7, boo puppy.jpg
)
I want to split this string to get my parameters out of it and it didn't work.
My code looked like this:
getline(cin, listOfCommands);
string functionToApply = listOfCommands.substr(0, listOfCommands.find(" "));
int position = listOfCommands.find(" ");
listOfCommands.erase(0, position + 1);
cout << listOfCommands;
if (functionToApply == "exit")
break;
else if (functionToApply == "add")
{
position = listOfCommands.find(", ");
string name = listOfCommands.substr(0, position);
listOfCommands.erase(0, position + 1);
position = listOfCommands.find(", ");
string breed = listOfCommands.substr(0, position);
listOfCommands.erase(0, position + 2);
position = listOfCommands.find(", ");
string birthDate = listOfCommands.substr(0, position);
listOfCommands.erase(0, position + 2);
position = listOfCommands.find(", ");
string nrShorts = listOfCommands.substr(0, position);
listOfCommands.erase(0, position + 2);
string photo = listOfCommands;
}
Can someone help me, please?