•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,808 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,684 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 158 | Replies: 2
![]() |
•
•
Join Date: Nov 2007
Posts: 46
Reputation:
Rep Power: 1
Solved Threads: 2
ok in what way do you separate the digits from a given int ??
like if the int is 987987
how do you separate them in to 9 8 7 9 8 7 ???
is there any function to do this ?
like if the int is 987987
how do you separate them in to 9 8 7 9 8 7 ???
is there any function to do this ?
Here's one of the easiest way of doing it
cplusplus Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> #include <sstream> using namespace std; void separate(int n) { stringstream s; char c; s << n; while (s.get(c)) cout << c << " "; //outputing the integer with the spaces } void main() { int n; cout << "enter number: "; cin >> n; separate(n); // calling separate function cout << endl; }
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C++ Forum
- Previous Thread: just incase anyone wanted to know how to do airline tickets
- Next Thread: How can i do error handling in getline()


Linear Mode