mardi 4 février 2020

Inserting numbers to a string

I have the following string

std::string str = "000000"

and I want to run a loop from 0 to 200 and insert the numbers in the string.

for( int i = 0 ; i < 200; i++ )
{
    // insert number
}

If i = 1, then the string should be "000001".

If i = 200, then the string should be "000200".

Currently I am casting my numbers to string and than I check their length. Based on that, I insert the numbers to the string if len = 1 and then replace the last char of the string.

Just wanted to know if I can have more refined approach to this.

Aucun commentaire:

Enregistrer un commentaire