据我所知,以下一行是将double十六进制输出到全精度所需要的:
std::cout << std::hexfloat << yourDouble << std::endl;
但是在Visual Studio 17中使用MSVC ++只能打印出双精度的十六进制数字。请参阅我的代码(为清晰起见,已将其删除):
std::ifstream cacheF(pToFile, std::ios::in);
if (!cacheF.is_open()) {
std::cerr << "Could not open " << pToFile << "!" << std::endl;
return 1;
}
bool readSuccess = true;
unsigned long long sumBegin, cached[2];
double previousTime;
readSuccess = readSuccess && (cacheF >> std::dec >> sumBegin);
readSuccess = readSuccess && (cacheF >> std::hexfloat >> previousTime);
for (int i = 0; i < 2; i++) readSuccess = readSuccess && (cacheF >> std::hex >> cached[i]);
cacheF.close();
if (!readSuccess) {
std::cerr << "Cache reload failed due to improper file formatting!" << std::endl;
}
std::cout << std::hexfloat << previousTime << std::endl;
std::cout << std::setprecision(13) << std::hexfloat << previousTime << std::endl;
输入文件如下:
1045644800006
0x1.567be0370cdc8p+7
C6CCFEDA2563B0D1
5E3492440B4BE8B2
输出为:
0x1.567be0p+7
0x1.567be0370cdc8p+7
自从我上次在GCC上尝试过以来已经有一段时间了,但是如果我没记错的话,它可以产生全双精度输出而无需setprecision。任何人都可以确认这是否是MSVC ++特定的行为,这是为什么吗?