我正在拼命尝试使用 fstream: 列来生成格式化输出。
有两个函数(无论函数 Func1,Func2)产生输出(写入同一个文件,“example.dat”):
#include <fstream>
int main()
{
std::ofstream fout;
fout.open("example.dat");
for (int i=0; i<10; i++)
{
fout << Func1(i) << std::endl;
};
// Func2 depends on Func1, thus them **cannot** be written at the same time:
// fout << Func1() << " " << Func2() << std::endl;
for (int i=0; i<10; i++)
{
fout << Func2(i) << std::endl;
};
return 0;
}
输出将类似于:
功能1(0)
功能1(1)
.
. .
功能1(9)
功能2(0)
函数2(1)
.
.
.
函数2(9)
我的问题是:如何将此输出生成为两列:
功能 1(0) 功能 2(0)
功能 1(1) 功能 2(1)
.
.
.
虽然它们不是同时写入的。
我怀疑我需要使用 seekp()、tellp(),但不幸的是我不是这方面的大专家。
请帮忙!
先感谢您。