C++ 关于向量&x27;格式c++;

C++ 关于向量&x27;格式c++;,c++,vector,format,C++,Vector,Format,我以这种方式将文件内容读入两个向量: ifstream file1; std::string line1; std::vector<double> x1, y1; file1.open(argv[1]); while (std::getline(file1, line1)) { double x = 0., y = 0.; sscanf (line1.c_str(), "%lf %le\n", &x, &y); printf("%.12lf %.17le\n", x

我以这种方式将文件内容读入两个向量:

ifstream file1;
std::string line1;
std::vector<double> x1, y1;

file1.open(argv[1]);
while (std::getline(file1, line1))
{
double x = 0., y = 0.;
sscanf (line1.c_str(), "%lf %le\n", &x, &y);
printf("%.12lf %.17le\n", x, y); //print on screen
x1.push_back(x); //fill vectors
y1.push_back(y);
}
file1.close();
ifstream文件1;
std::字符串行1;
std::向量x1,y1;
文件1.打开(argv[1]);
while(std::getline(file1,line1))
{
双x=0,y=0。;
sscanf(line1.c_str(),%lf%le\n“,&x,&y);
printf(“%.12lf%.17le\n”,x,y);//在屏幕上打印
x1.向后推(x);//填充向量
y1.推回(y);
}
file1.close();
当我在屏幕上打印它们时,我可以指定我想要的格式,以便它们与文件中的格式完全相同; 但当我使用“push_back”填充向量时,我失去了原始格式,x1和y1以一种对我后续计算没有用处的方式进行了近似。 如何将原始格式传递给x1和y1? 提前谢谢! 埃琳娜

你说的“放松原始格式”是什么意思?内部,, 浮点不存储为字符串,并且没有跟踪 输入时使用了什么格式。这是必要的,以便
这些值可以用于后续的计算。

几乎可以肯定是由于浮点精度。每一位计算机科学家都应该知道的关于浮点运算的知识,作者:David Goldberg-