I'm working on a program that handles "integers" that are too long to be legal integers in C++. I've got most of it handled, but in testing, I discovered that if I get an input as a numerical value where the number of digits is exceptionally long, the compiler uses the typical maximum or minimum value of an integer (32,767) and I get an unrecognizable number. This is exactly what the program is meant to handle.
For example, say I get the number 1000000945831 (totally made up for testing). If I get that number passed as a string, I'm fine. My program can handle it. But if that number gets passed as an number, things break down.
What I was trying to do (successfully with smaller numbers), was to use a stringstream like this:
1 2 3 4 5 6 7
|
<class>::<class>(int myValue) //constructor
stringstream ss;
string strMyValue
ss << myValue
strMyValue = ss.str();
|
As I said, this works fine with smaller numbers, but the whole point is to handle very large numbers. If someone were to call this like:
1 2 3
|
int main()
<class> <object>(1000000945831)
|
the number that enters the stringstream has been converted due the limitations with integer handling. Is there another way to handle this so that I don't lose the initial value? I'm a little stumped.
Thanks.