After reading the Bignum challenge I thought i'd give it a go :D
I'm currently trying to store the digits in a vector and outputting them.
An easy task, so I thought. But I keep having this weird error.
this is my code, the constructor and the print function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
bigint(string str = "")
{
string::iterator itr = str.begin();
while(itr < str.end())
{
int x = *itr;
digits.push_back(x);
itr++;
}
};
void print()
{
for(int i = 0; i < digits.size(); i++)
cout<<digits[i];
}
I just call them both, giving "12345" as argument.
This is my output: 4950515253
It seems as if the 5 is alternating with diff digits...
You're getting the ascii codes for the integer values, ie:
1 = ascii 49
2 = ascii 50
etc...
Make line #6 int x = *str - '0'; ( subtracting the ascii value for 0 ) and you should be good to go.