123456789101112
#include <string> #include <iostream> int main() { std::string n; std::cout << "Enter number: "; std::cin >> n; for (const auto& c : n) std::cout << c << '\n'; }
Enter number: 123 1 2 3
123456789101112131415161718
#include <iostream> #include <string> int main() { std::cout << "Enter a number: "; int num { }; std::cin >> num; // std::to_string requires C++11 or later // https://en.cppreference.com/w/cpp/string/basic_string/to_string std::string num_str { std::to_string(num) }; for (const auto& itr : num_str) { std::cout << itr << '\n'; } }