code.cpp 526 B

1234567891011121314
  1. /* Create a function that accepts a string
  2. * (of a persons first and last name) and returns a
  3. * string with the first and last name swapped.
  4. * There will be exactly one space between the first and last name.
  5. */
  6. std::string nameShuffle(std::string str) {
  7. // find the space
  8. int sFind = str.find(' ');
  9. // create a substring for the first name
  10. std::string first = str.substr(0,sFind);
  11. // create a substring for the last name
  12. std::string second = str.substr(sFind+1,str.size()-1);
  13. return second + ' ' + first;
  14. }