display on separate lines

The user gives a whole number.Print digits on separate lines.
example he gives 12456.
result
1
2
4
5
6



1
2
3
4
std::string x;
std::cin >> x;
for(char c: x)
    std::cout << x << std::endl;
Last edited on
I think that the purpose of the assignment is to learn to write recursive functions. You should write a recursive function that displays digits of a number in the direct order.
Last edited on
1
2
3
4
std::string x;
std::cin >> x;
for(char c: x)
    std::cout << x << std::endl;

this dont work.

vlad - this task is to learn loop
What error did you get? Note that I made a mistake in my previous post: in last line it should be c instead of x. Probably you have an outdated compiler. If so next code will help you.
1
2
3
4
5
std::string x;
std::cin >> x;
for(char c: x)
for(int i = 0; i < x.size(); ++i)
    std::cout << x[i] << std::endl;

Last edited on
thank you ..i have dev c++
Topic archived. No new replies allowed.