C++ integer digits to line by line -


i working project convert integer value each line. example:

23487 

output be

2 3 4 8 7 

i know code if used string, think better if use integer.

my current code using string:

#include <iostream> #include <string> using namespace std; int main() { string str("23487"); (int = 0; < str.size(); i++){     cout << str[i] << endl; } system("pause"); return 0; } 

can me if use int instead of string?

for integer values larger 0, can use this:

void print(int val) {     if (val > 0)     {         print(val/10);         cout << val%10 << endl;     } } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -