我拼命试图通过使用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;
}
输出将类似于:
FUNC1 (0)
Func1(1)
。
。 。
FUNC1(9)
FUNC2(0)
FUNC2(1)
。
。
。
FUNC2(9)
我的问题是:如何产生这种输出作为两列:
FUNC1(0)FUNC2(0)
FUNC1(1)FUNC2(1)
。
。
。
虽然它们不是同时写入。
我怀疑我需要使用seekp(),tellp(),但不幸的是我不是这方面的大专家。
请帮忙!
预先感谢您。
你就不能缓冲FUNC1和FUNC2的输出分为2'载体'这样就可以输出结果在一个循环columnated? –
Benj
谢谢BENJ, – Pomeron
您应该编辑您的问题,从标题中删除(C++)。如果您拥有C++标记,则不需要将其放入。 – tinman