istream >> float, trailing "e"

Rasmus Kaj kaj@e.kth.se
Mon Nov 25 06:19:00 GMT 2002


I want to read a float directly followed by a string from an istream,
using gcc 3.2 (the string is the unit for the float value).  This
works just fine for most units:

  float value;
  string unit;
  if(in >> value >> unit) { ok, use it ... }

However, if the unit happens to start with an "e", the float extractor
includes this "e" in the string to convert to a float, thinking it
marks the exponent part.  Then the conversion fails, because the
actual exponent is missing.

So I tried adding "in.setf(ios::fixed, ios::floatfield);" before the
extraction, but it had no effect.

Shouldn't the float extractor put back the "e" when there is no digits
after it?  Or shouldn't the "e" stop the extraction if I say I want a
number in fixed format?  Or is fixed format only allowed for output?
Is this a bug in gcc, or am I simply missing something?

Any help appreciated, please cc me, as I'm not subscribed to the list.


-- 
Rasmus Kaj ----------------------------------------------- rasmus@kaj.se
 \ To make an apple pie from scratch, first create the universe -C Sagan
  \------------------------------------- http://www.stacken.kth.se/~kaj/



More information about the Gcc-help mailing list