#include <iostream>
#include <string>

int main()
{
    std::string Track2 = ";80221000000100018A1301000000000000000?";
    std::string end_character = "?";

    std::cout << "Before: Track2 = \"" << Track2 << "\"\n";

    if (Track2.length() > 24)
    {
        auto question_mark_pos = Track2.find_first_not_of('0', 24);
    
        // If there is a character after the zeros AND
        // if that character is last AND
        // if that character is a question mark
        if (question_mark_pos != std::string::npos &&
            question_mark_pos == Track2.length() - 1 &&
            Track2[question_mark_pos] == '?')
        {
            // Get the first 24 characters of the string
            Track2 = Track2.substr(0, 24);
    
            // And append the special end character
            Track2 += end_character;
        }
    }

    std::cout << "After: Track2 = \"" << Track2 << "\"\n";

}
