Handling huge numbers

Hello friends,


I'm currently doing Project Euler Challenge 8 where you have to find the largest product of a series of 5 digits in a 100 digit number.

The code is obviously very basic, but I have a problem getting C++ to read in the very huge integer since long_int is not big enough to store it.
Now I could obviously type in every single digit by itself and it would run but there has to be a more elegant way to do this!

Despite doing some web research (Do I have to write a class?) I have not found a satisfactory answer for my problem.

All Answers are welcome! Thanks in advance.
I used a string to store the 100 digit number.

That way, it's easier to pluck digits out of it (you don't have to resort to division/modulus), and you also don't have to use an arbitrary-precision library (or write your own).
@long double

I guess you used stringstream then?

Sorry for "silly questions" my C++ knowledge is still very basic.
No, I just used a for loop:
1
2
3
4
5
6
for (unsigned i = 0; i + 5 < my100DigitNum.size(); ++i)
{
    // Now work with my100DigitNum[i], my100DigitNum[i+1], ... , my100DigitNum[i+4] here
    // Note that you'll have to convert them from their character form to ints
    // Subtracting '0' from the character should work for most people
}
Great, thank you.
Topic archived. No new replies allowed.