fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. void ChangeString(std::string& test)
  5. {
  6. bool inbracket = false;
  7. std::string outStr;
  8. for (size_t i = 0; i < test.size(); ++i)
  9. {
  10. char ch = test[i];
  11. if (ch == '[')
  12. inbracket = true;
  13. else
  14. if ( ch == ']')
  15. inbracket = false;
  16. else
  17. if ( !inbracket )
  18. outStr += ch;
  19. }
  20. test = outStr;
  21. }
  22.  
  23. using namespace std;
  24.  
  25. int main()
  26. {
  27. std::string test = "[12]1234[56]78";
  28. ChangeString(test);
  29. cout << test;
  30. }
  31.  
  32.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
123478