-2

I have built a method that receives a line and the line is in the next format:

name, id, type, videos list

name, id and type are fixed but my problem is that there are more then 1 video and I want to enter them into a list. I know how to enter them to a list but my question is how can Iterate over the line from the start of the videos list string to the end of it.

So far my code is:

Client* deseriallize_client(std::string str)
{
int index = str.find(",");
std::string name = str.substr(0, index);
str.erase(0, index + 1);

index = str.find(",");

std::string id = str.substr(0, index);
str.erase(0, index + 1);

index = str.find(",");
std::string type = str.substr(0, index);
str.erase(0, index + 1);

Client *new_client = new Client(name,id,type);

I build the Client class and it also has a method called add_vid.

so for example lets say the text contains :

User,300,vip,Fight Club, The shawshank redemption,Lucky number slevin ,seven

I want to know how to write an iteration which will do:

new_client.add_vid(Fight Club)
new_client.add_vid(The shawshank redemption)
....
eightShirt
  • 1,457
  • 2
  • 15
  • 29
Man in Black
  • 89
  • 2
  • 2
  • 12
  • 1
    [Split a string in C++](https://stackoverflow.com/questions/236129/split-a-string-in-c) and [Parsing a comma-delimited std::string](https://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring) – Cory Kramer Aug 17 '15 at 12:30

1 Answers1

0
  1. Check if there is a comma in the string. If not, add it, and stop.
  2. Add the string before the comma.
  3. Copy the string after the comma into the string.
  4. Go to step 1.
David Schwartz
  • 179,497
  • 17
  • 214
  • 278