I have a string line containing a full name i.e. "John E Baker"
I want to break it down into smaller strings: FirstName, LastName and MiddleInitial.
I need to write a function that will do this. However this fucntion needs to be versatile becasue it will recieve the line string several time and each time it will be different.
So for instance when the first lien is processed the main program will loop and a new string will be read into the function i.e. "Michael B Burns"
How can I write the fucntion code to break down any string line into three substrings firstname lastname and middle initial?
You could use a stringstream.
string line = "John E Baker";
string a, b, c;
ss >> a >> b >> c;
Of course, middle initial is optional, so this code could require some tweaking if there is just "firstname lastname".
Last edited on