1234567891011121314 |
- /* Create a function that accepts a string
- * (of a persons first and last name) and returns a
- * string with the first and last name swapped.
- * There will be exactly one space between the first and last name.
- */
- std::string nameShuffle(std::string str) {
- // find the space
- int sFind = str.find(' ');
- // create a substring for the first name
- std::string first = str.substr(0,sFind);
- // create a substring for the last name
- std::string second = str.substr(sFind+1,str.size()-1);
- return second + ' ' + first;
- }
|