Hi,
I am trying the following code but putback() apparently is returning a character and it destroy my number .
I thought about saving the current position in the text file before in >> c
and then use return back if not correct .
I am not sure how to do that .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
char c;
int n;
// read from text file
in >> c;
if ((c >='a' && c <= 'z') || ((c >= 'A') && (c < 'Z')))
{
currentUser=c;
cout << "executionTime is : " << currentUser <<endl;
in >> childProcess;
time1 = timePerUser/childProcess;
idTemp=0;
}
else{
in.putback (c);
in >> n;
Using std::istream::peek() would be easier. Something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int next ;
while( ( next = istm.peek() ) != std::char_traits<char>::eof() )
{
if( std::isdigit(next) )
{
int number ;
istm >> number ;
// use number
}
else
{
std::string str ;
istm >> str ;
// use str
}
}