fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. size_t i, j, len;
  8. string str, str2;
  9.  
  10. cout << "Enter string: ";
  11. getline(cin, str);
  12.  
  13. str2 = str;
  14. len = str2.length();
  15.  
  16. i = 0;
  17. while (i < len)
  18. {
  19. if (str2[i] == ' ')
  20. {
  21. for (j = i + 1; j < len; ++j)
  22. {
  23. str2[j - 1] = str2[j];
  24. }
  25. --len;
  26. }
  27. else
  28. ++i;
  29. }
  30.  
  31. str2.resize(len);
  32.  
  33. cout << str2 << endl;
  34.  
  35. //system("pause");
  36. return 0;
  37. }
Success #stdin #stdout 0s 4360KB
stdin
Hello World    is this working?
stdout
Enter string: HelloWorldisthisworking?