In C++, I have the following input: 12345
How can I achieve this output: 1 2 3 4 5
?
Another example could be:
input: 123
output: 1 2 3
In C++, I have the following input: 12345
How can I achieve this output: 1 2 3 4 5
?
Another example could be:
input: 123
output: 1 2 3
You can simply do this:
int num = 123;
std::vector<int> digits;
while( num > 0 ) {
digits.push_back(num % 10);
num /= 10;
}