This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
istream >> float, trailing "e"
- From: Rasmus Kaj <kaj at e dot kth dot se>
- To: gcc-help at gcc dot gnu dot org
- Cc: Rasmus Kaj <kaj at e dot kth dot se>
- Date: 25 Nov 2002 15:19:09 +0100
- Subject: istream >> float, trailing "e"
- Organization: http://www.stacken.kth.se/ - Stacken computer club, Stockholm
- References: <rqc1y59wx8b.fsf@envy.e.kth.se>
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/