I need to read in a very long Int into a Long Int class I'm making right now and I am overloading the cin >>
operator. The user must enter the entire number at once. For example: 444444444444444444444444444
I was planning to use cin.get()
and cast the result into an int
just so I can grab the first 4
from the stream, but it is NOT working. Can someone please help me with any tips/suggestions?
istream& operator>>(istream &input, LongInt &longint)
{
int check; ////
int first;
first = (int)(cin.get());
longint.stack_li.push(first);
cout << first;
//while (isdigit((int)(input.peek())))
//{
// longint.stack_li.push((int)(check = input.get()));
// cout << check;
//}
return input;
}
(stack_li
is just a stack
from a header file I included (Not the STL's) and I made the stack
a private variable of the class LongInt
belongs to.) When I enter the number 5796 as a long int
when my program runs, the output is 55 or 57 or some random 2 digit number, something is clearly wrong. Please let me know!!
Thank you very much!!