fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. int main(int /*argc*/, const char** /*argv*/)
  5. {
  6. std::string stringOne = "http://google.com/logo.jpg C:\\windows\\user\\Desktop\\logo.jpg";
  7. std::string stringTwo = "", stringThree = "";
  8.  
  9. size_t spacePos = stringOne.find(' ');
  10. if (spacePos != std::string::npos) {
  11. // copy 0-spacePos, i.e. all the chars before the space.
  12. stringTwo.assign(stringOne, 0, spacePos);
  13. // copy everything after the space.
  14. stringThree.assign(stringOne, spacePos + 1, std::string::npos);
  15. }
  16.  
  17. std::cout << "s1 = \"" << stringOne << "\"" << std::endl;
  18. std::cout << "s2 = \"" << stringTwo << "\"" << std::endl;
  19. std::cout << "s3 = \"" << stringThree << "\"" << std::endl;
  20. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
s1 = "http://google.com/logo.jpg C:\windows\user\Desktop\logo.jpg"
s2 = "http://google.com/logo.jpg"
s3 = "C:\windows\user\Desktop\logo.jpg"