I have a string of numbers in C++: like string str="1234567012"
I wish to copy this to an int array, such that each element of the array will have one digit. Now I can use an iterator, and iterate one at a time and use
static_cast<int>(*iter). But is there any more easier and straightforward method?finally i want to recopy the int array to a string array.
Please help me with above 2 steps.
You can use the
std::transformfunction:If your compiler doesn't support lambdas yet, you can use a regular function:
To do the reverse operation, you can do similarly: