Question: Please write a function in C++ named nextString that will return a single 'value' (i.e. substring) from a Comma Separated Value string. Your function will

Please write a function in C++ named nextString that will return a single 'value' (i.e. substring) from a Comma Separated Value" string. Your function will take two arguments: a string variable containing a comma separated list of values, and an integer containing the starting index; your function should return a single string object with the value that starts at that index and ends right before the next comma ',' (do not include the comma in the returned string!) :

string nextString(string str, int start_index);

If, however, the start index is after the last comma in the string, then the function should return the value starting at that index and continuing to the end of the string.

For example,

cout << nextString("my,cat,ate,my,homework",3);

will print (cat)

and

cout << nextString("my,cat,ate,my,homework",8);

will print (te)

and

cout << nextString("my,cat,ate,my,homework",18);

will print (work)

When you have written your function, then write a short test program that will take in a simple comma separated string using getline: getline(cin,somestring) and output values in the string using the nextString function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!