You can simply do this:
int num = 123;
std::vector<int> digits;
while( num > 0 ) {
digits.push_back(num % 10);
num /= 10;
}
More Related Contents:
- C++ Looping / Array
- Is there a way to create a c++ gui game without win32 api, openGL, direct X and stuff? [closed]
- Why is sizeof giving incorrect number of bytes in C++?
- Inheriting constructors
- Array of zero length
- Passing object by reference to std::thread in C++11
- Const before or const after?
- Finding current executable’s path without /proc/self/exe
- What is the C++ iostream endl fiasco?
- How to render offscreen on OpenGL? [duplicate]
- What’s “wrong” with C++ wchar_t and wstrings? What are some alternatives to wide characters?
- Tail recursion in C++
- Why do I see strange values when I print uninitialized variables?
- c++ compile error: ISO C++ forbids comparison between pointer and integer
- How to write to a memory buffer with a FILE*?
- Count character occurrences in a string in C++
- How to initialize 3D array in C++
- Self-initialization of a static constexpr variable, is it well-formed?
- Are notes and examples in the core language specification of the C++ Standard non-normative?
- Explanation of function pointers
- Detect Windows or Linux in C, C++ [duplicate]
- Do these members have unspecified ordering?
- Has the new C++11 member initialization feature at declaration made initialization lists obsolete?
- Using boost::iostreams::mapped_file_source with std::multimap
- C++ Return value, reference, const reference
- Returning non-const reference from a const member function
- array of pointers as function parameter
- How much overhead is there when creating a thread?
- How to check if a process has the administrative rights
- What does an extra 0 in front of an int value mean?