So I have a lab problem I need help with. I need to write a function that has a name parameter that includes the person's entire name. Ex) "John Quincy Doe". From that input, my function has to return the last name with a comma, then the first name and middle initial. Ex) "Doe, John Q". I have the right idea of checking for space and then breaking them into substrings, but how do I go about doing that in C++?
Asked
Active
Viewed 62 times
2 Answers
2
That is commonly called tokenizing a string. There are multiple answers on here. I would just comment, but apparently I can't until I have 50 reputation.
0
Depending on whether you are allowed to use it, you could also implement your function with a regular expression that matches three parts of the name and uses the sub matches in the correct order resp. with only the first letter of the second match, e.g. the middle name.

blackbird
- 957
- 12
- 18