我正在尝试从c ++中的文本获取值(所有十进制数字)。但我有一个问题,我无法解决
#include "pch.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main()
{
std::ifstream infile("C:\\thefile.txt");
float a, b;
while (infile >> a >> b)
{
// process pair (a,b)
}
std::cout << a << " " << b;
}
Run Code Online (Sandbox Code Playgroud)
thefile.txt:
34.123456789 77.987654321
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,
a = 34.1235
b = 77.9877
Run Code Online (Sandbox Code Playgroud)
但我想要
a = 34.123456789
b = 77.987654321
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
编辑:我不想打印出a和b。我只希望他们得到确切的值。