Search code examples
c++istreamistringstreammanipulators

istream manipulators for reading double


I need to read numbers like 14.3925125E from istringstream as part of formatted input. E meaning east, not scientific notation.
When I try to use input >> double >> char it looks like the stream takes the number as wrong scientific and fails. I tried manipulators std::fixed and std::dec but it didn't help. Is there something else i can use?


Solution

  • Manipulators won't do it, because E is part of how floating point values are represented as text. For example 14.25E2 represents the value 1425.00.

    You need to extract substrings and parse them separately. Without error checking, something like ....

    std::string input("14.3925125E");
    std::string substring = input.substr(0, input.find('E'));
    std::istringstream str(substring);
    str >> double_value;