fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. std::string Track2 = ";80221000000100018A1301000000000000000?";
  7. std::string end_character = "?";
  8.  
  9. std::cout << "Before: Track2 = \"" << Track2 << "\"\n";
  10.  
  11. if (Track2.length() > 24)
  12. {
  13. auto question_mark_pos = Track2.find_first_not_of('0', 24);
  14.  
  15. // If there is a character after the zeros AND
  16. // if that character is last AND
  17. // if that character is a question mark
  18. if (question_mark_pos != std::string::npos &&
  19. question_mark_pos == Track2.length() - 1 &&
  20. Track2[question_mark_pos] == '?')
  21. {
  22. // Get the first 24 characters of the string
  23. Track2 = Track2.substr(0, 24);
  24.  
  25. // And append the special end character
  26. Track2 += end_character;
  27. }
  28. }
  29.  
  30. std::cout << "After: Track2 = \"" << Track2 << "\"\n";
  31.  
  32. }
  33.  
Success #stdin #stdout 0s 3060KB
stdin
Standard input is empty
stdout
Before: Track2 = ";80221000000100018A1301000000000000000?"
After: Track2 = ";80221000000100018A13010?"