C++ has an I/O manipulator called 'fixed' to input/output floating-point numbers in fixed (non-scientific) form. It works fine for output, but I don't understand how to get input working properly.
Consider this example:
#include <sstream>
#include <iostream>
using namespace std;
int main() {
double value;
istringstream("1.4e1") >> fixed >> value;
cout << value << endl;
}
In my opinion, it should work like this. Input stream has some string. When we apply fixed
manipulator on it and try to read a double/float, it should stop on a first character which is not a digit or a dot (dot is not accepted second/third/more times). So, correct output would be 1.4
(we stop processing input when we encounter 'e'
).
Instead, this code outputs 14
. Why? How it works and what is the purpose of fixed
for input streams? How can I read a double from input stream and stop at 'e'
(leave it in input stream)?