fork download
  1. #include <sstream>
  2. #include <string>
  3. #include <iostream>
  4. void old_code()
  5. {
  6. std::stringstream concat;
  7. std::string txtFullPath = "Path here";
  8. concat.str("");
  9. concat << txtFullPath;
  10.  
  11. std::stringstream& p = concat;
  12. std::cout << p.str() << '\n'; //First path above
  13. std::stringstream path;
  14. path.str(p.str()); // does not advance the put pointer.
  15. path << "Ship01.tga"; // writes to characters starting at path.str()[0]
  16. std::cout << "Loading player ship from " << path.str() << '\n';
  17. }
  18. void new_code()
  19. {
  20. std::stringstream concat;
  21. std::string txtFullPath = "Path here";
  22. concat.str("");
  23. concat << txtFullPath; // this makes it work
  24.  
  25.  
  26. std::stringstream& path = concat;
  27. std::cout << path.str() << '\n';
  28. path << "Ship01.tga";
  29. std::cout << path.str() << '\n';
  30. }
  31. int main()
  32. {
  33. std::cout << "old code: \n";
  34. old_code();
  35.  
  36. std::cout << "new code: \n";
  37. new_code();
  38. }
  39.  
Success #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
old code: 
Path here
Loading player ship from Ship01.tga
new code: 
Path here
Path hereShip01.tga