Tuesday, 1 October 2013

Bigint operator >> overload

Bigint operator >> overload

Here is my code for my operator>> overload. It is supposed to take the
numbers up to a semicolon and put them into a bigint.
std::istream& operator>>(std::istream& is, bigint& bi) {
int i = 0;
char ch;
char temp[SIZE];
// grabs the first character in the file
is >> ch;
temp[i] = ch;
++i;
// while loop grabs the rest of the characters
// up to the semicolon
while(ch != ';') {
is >> ch;
temp[i] = ch;
++i;
}
// temp is stored in the bigint ref
bi = bigint(temp);
return is;
}
The problem I'm having is that when I run it, it gives me extra output.
For example: when I type in "34;" as the input, the resulting bigint will
be "3411". Can anyone tell me what I'm doing wrong?

No comments:

Post a Comment