fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::string addTwoStrings(const std::string& a, const std::string& b)
  5. {
  6. return a + b; // works because they are both strings.
  7. }
  8.  
  9. void foo(const char* a, const char* b)
  10. {
  11. std::string str = a;
  12. std::cout << "1st str = [" << str << "]" << std::endl;
  13. str += " ";
  14. std::cout << "2nd str = [" << str << "]" << std::endl;
  15. str += b;
  16. std::cout << "3rd str = [" << str << "]" << std::endl;
  17. str = addTwoStrings(a, " ");
  18. std::cout << "4th str = [" << str << "]" << std::endl;
  19. str = addTwoStrings(str, b);
  20. std::cout << "5th str = [" << str << "]" << std::endl;
  21. }
  22.  
  23. int main()
  24. {
  25. foo("hello", "world");
  26. }
  27.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
1st str = [hello]
2nd str = [hello ]
3rd str = [hello world]
4th str = [hello ]
5th str = [hello world]