Dear friends,
I appreciate any feedback on this problem.
I am trying to be able to produce an output with first, middle, and last name using a const string value. Therefore, no matter what name is use on the const string value, it should always display the full name.
So far, I have been able to get the first name correctly. However, when I try to get the middle name, it wraps the last name as well...
Thanks for your any valuable advise.
I appreciate any feedback on this problem.
I am trying to be able to produce an output with first, middle, and last name using a const string value. Therefore, no matter what name is use on the const string value, it should always display the full name.
So far, I have been able to get the first name correctly. However, when I try to get the middle name, it wraps the last name as well...
Thanks for your any valuable advise.
Code:
#include <iostream> #include <string> using namespace std; const string name = "John Paul Jones"; int main() { int spacePos = name.find(' '); // int len = name.length(); string firstName = name.substr(0, spacePos); string middleName = name.substr(spacePos + 1); cout << firstName + ' ' << middleName << endl; return 0; }
Comment