gonzaga1751

Member
Aug 16, 2005
175
0
0
learning c++ so not to good
but i need to know how to find the length of an integer and set that integer to an array and just can't seem to figure it out don't know a lot of the libraries that could help so something simply would be nice

so say int i = 1234

see that there are four numbers long
an array that has for example int a = l1l2l3l4l

thanks
 

Templeton

Senior member
Oct 9, 1999
467
0
0
For a more c++ish aproach: (Note: like previous solution, this is assuming that you want an array of character values, not actual integers)

 

Matthias99

Diamond Member
Oct 7, 2003
8,808
0
0
see also: itoa() (Integer To ASCII), and atoi() (ASCII to Integer). These are from old-fashioned C, and work on raw char* buffers rather than std::string and std::stringstream. Note that only atoi() is part of the ANSI C spec; itoa() is pretty widely supported, but may not be in all compiler packages, especially older ones.

Also, in the post right above mine, I think you want

i >> buffer;

or

buffer << i;

and not

buffer >> i;

Unless std::stringstream defines the << and >> operators VERY strangely.