#include #include using namespace std; int main() { // save the cout format flags ios_base::fmtflags originalFlags = cout.flags(); double f = 1234.5678; cout << "Default output: " << f << endl; cout << "fixed: " << fixed << f << endl; cout << "scientific: " << scientific << f << endl; cout << "hexfloat: " << hexfloat << f << endl; cout << "default: " << defaultfloat << f << endl; // read hexfloat format into a double istringstream("0x1P-1022") >> hexfloat >> f; // display the double in default format cout << "Parsing 0x1P-1022 as hex gives " << f << '\n'; f = 3.141592654; cout << f << " as hexfloat: " << hexfloat << f << endl; // save hexfloat value into a string ostringstream sout; sout << hexfloat << f << endl; // save the hexfloat value into an input string buffer istringstream sin; sin.str(sout.str()); // read the input string buffer into a double sin >> hexfloat >> f; // display f cout << f << endl; // display f in original format cout.flags(originalFlags); cout << f << endl; }