+ 6
A simple method would be to convert it back to int, add your number, then convert back to string
2nd Feb 2022, 10:40 AM
Rishi
Rishi - avatar
+ 3
You can also get help from std::stoi() std::string n { std::to_string( 4 ) }; // "4" n = std::to_string( std::stoi( n ) + 4 ); // "8"
2nd Feb 2022, 12:41 PM
Ipang
0
If you know that there will be no carry when you add, then you can shift the character value by 4. string n = "4"; n[0] += 4; cout << n; //output: "8"
8th Feb 2022, 5:08 PM
Brian
Brian - avatar