I have to overwrite the operator>>. The conditions is to take in an numbers and store it into an array until the file contains a ';' from a .txt file.
file ex.
1018929238387; 29323867;
387374848938948747
3837474838734;
I am completely lost and really need help. I have never worked with .txt files and this is my first time overriding the >> operator. I do not know how to work with whitespaces and endlines to skip them from a file.
switch(ch) {
case'0':
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'8':
case'9':
bigint_data_array.add(ch); // or whatever you need to do to add to the array
break;
case';':
semi = true;
break;
default:
// ignore
break;
}
char ch ;
while( in.get(ch) ) // get the next character
{
// if it is a decimal digit, add the digit to the array
if( std::isdigit(ch) )
{
int digit = ch - '0' ;
// add digit to array
}
// if it is a ; or a white space, throw it away and end the loop
elseif( ch == ';' || std::isspace(ch) ) break ;
else // if it is any other character, there is an arror
{
in.putback(ch) ; // put the character back into the input stream
in.setstate( std::ios_base::failbit ) ; // put the stream in a failed state
break ; // and end the loop
}
}