对于一个项目,我应该一次从输入文件中提取 3 个浮点变量,使用它们,然后再提取 3 个并重复,直到文件中没有更多变量。我尝试使用下面的这段代码来拉取它们(我已经打开了输入文件进行阅读),但它不起作用。我使用重载函数 openFile 创建了一个头文件,它将打开输入和输出文件并检查它们是否成功打开。
最小可重现示例
int main(int argc, char* argv[])
{
float a, b, c, root1, root2;
ifstream input;
if (openFile(input, argv[1]))
{
while (input >> a >> b >> c)
{
ofstream output;
openFile (output, argv[2])
root1 = a+b+c //for example
root2 = a-b-c //for example
output << a << b << c << root1 << root2 << endl;
}
input.close()
output.close()
}
}