How can I split an int in c++ to its single numbers? For example, I\'d like to split 23 to 2 and 3.
I don't necessarily recommend this (it's more efficient to work with the number rather than converting it to a string), but it's easy and it works :)
#include
#include
#include
#include
#include
int main()
{
int n = 23984;
std::string s = boost::lexical_cast(n);
std::copy(s.begin(), s.end(), std::ostream_iterator(std::cout, "\n"));
return 0;
}