#include <iostream>
#include <iomanip>
#include <cstdlib>
int main() {
double newVal ;
std::string str3 = "1.242699143";
std::stringstream os;
os << str3.c_str();
os >> std::fixed >> std::setprecision(16) >> newVal;
std::cout << newVal << "\n";
return 0;
}
您指定将
string
解析为 double
的精度,但未指定 double
的输出的任何精度。两种完全不同的东西。 IIRC,输出的默认精度是 6。试试这个:
std::cout << std::fixed << std::setprecision(10) << newVal << '\n';