Hi, I have a huge continuous number (thousands of digits long) in a .txt file and I need to store it a digit at a time in a vector. This is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <fstream>
#include <vector>
int main()
{
std::vector<int> Digits;
std::ifstream r("bignumber.txt");
int x;
while (r >> x) //"&& (r < 10)" doesn't work.
Digits.push_back(x);
for (int i=0;i<Digits.size();i++)
std::cout << Digits[i]; //Printing out for testing purposes, all I get is a bunch of -2147483648s, probably because the huge number is way bigger than the int limit.
}
If the number was at least somewhat more manageable, I could store it in a variable and then use the modulo operation to break it down to digits, but it's not possible in this case. If you have any ideas on how to do this, don't hesitate to write. Thanks!
Either that doesn't help me in any way, shape, or form while dealing with vectors or I'm just too oblivious to what is written in that page. I'm not sure which is true.
char c; // char read will be an ASCII value
while (r.get(c)) // loop getting single characters until EOF
Digits.push_back (c-'0'); // We want to convert the ASCII value to a binary digit