C ++ has an I / O manipulator called “fixed” for I / O floating point numbers in a fixed (unscientific) form. It works great for output, but I don’t understand how to enter input correctly.
Consider the following example:
#include <sstream> #include <iostream> using namespace std; int main() { double value; istringstream("1.4e1") >> fixed >> value; cout << value << endl; }
In my opinion, this should work like this. The input stream has some string. When we use the fixed manipulator on it and try to read double / float, it should stop at the first character, which is not a digit or a point (the point is not accepted second / third / more). Thus, the correct output will be 1.4 (we stop processing input when we encounter 'e' ).
Instead, this code outputs 14 . What for? How does it work and what is the fixed purpose for input streams? How can I read the double input stream and stop at 'e' (leave it in the input stream)?
source share