![]() |
Re: Need help with C++ please
Quote:
Honestly I can't describe how much I appreciate all your help guys! I keep on saying this over and over again.. This is why I really love this community! Very helpful in everyway. |
Re: Need help with C++ please
Quote:
And be sure it can handle the number 0 (which still takes 1 character to print on-screen). It is an easy one to miss when you're focusing on testing bigger numbers. Using standard library functions, depending on what you know about the input number type, a perhaps easier mathematical approach could be to use log10(i)+1 but it's still up to you to handle negatives, floats, etc. Taking the "convert it to a string and count the characters" approach, in C++11, my everyday choice would be to simply do: to_string(i).length() to_string is implemented in the C++ standard library as a wrapper around snprintf which then converts the result from a c-style character array and returns a std::string. So, following with woody's suggestion, you could pretty easily implement something like that yourself even in an older compiler which lacks C++11 support. This should be able to handle any type of number you throw at it. |
Re: Need help with C++ please
Quote:
So for the time being I 'teach' like this, in passing, when someone seems like they could use it or are interested. Quote:
Quote:
|
Re: Need help with C++ please
Quote:
Quote:
|
Re: Need help with C++ please
Quote:
|
All times are GMT. The time now is 16:49. |
vBulletin® Version 3.8.8