F
Fred Ma
I'm using the stringstreams to get the numerical values of string
tokens (the strings result from tokenizing a line of input elsewhere):
#include <iostream>
#include <sstream>
using namespace std;
int main(void)
{
istringstream iss("1.23DOG");
float flt;
cout << "isspos0=" << iss.tellg() << "\n" ;
iss >> flt;
cout << "flt=" << flt << "\n";
cout << "isspos0=" << iss.tellg() << "\n" ;
return 0;
};
This generates:
isspos0=0
flt=1.23
isspos0=4
I'm reading lots of warnings against interpreting tellg() as a an
integral type, or as a byte offset from the beginning of the stream.
This seems to be in the context of multibyte file streams, or file
streams in microsoft text files, where two bytes are used to signify
the end of line.
For my purposes, I just want to use tellg() to determine if there are
any residual characters left in the token, in which case I consider
the token to be illegal. Is this "evil"? I don't anticipate dealing
with multibyte data.
Thanks.
Fred
tokens (the strings result from tokenizing a line of input elsewhere):
#include <iostream>
#include <sstream>
using namespace std;
int main(void)
{
istringstream iss("1.23DOG");
float flt;
cout << "isspos0=" << iss.tellg() << "\n" ;
iss >> flt;
cout << "flt=" << flt << "\n";
cout << "isspos0=" << iss.tellg() << "\n" ;
return 0;
};
This generates:
isspos0=0
flt=1.23
isspos0=4
I'm reading lots of warnings against interpreting tellg() as a an
integral type, or as a byte offset from the beginning of the stream.
This seems to be in the context of multibyte file streams, or file
streams in microsoft text files, where two bytes are used to signify
the end of line.
For my purposes, I just want to use tellg() to determine if there are
any residual characters left in the token, in which case I consider
the token to be illegal. Is this "evil"? I don't anticipate dealing
with multibyte data.
Thanks.
Fred