This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

istream >> float, trailing "e"


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]