我以前做过这个,但找不到示例代码......对 C++ 来说还是新手。
我需要将多行输出到文本文件。现在它只输出最后一行,所以我假设每次运行循环时它都会覆盖前一行。如何让它输出一行,然后输出到下一行,等等,而不覆盖前一行?
这是一个片段:
int main()
{
int n = 1;
while (n <= 100)
{
int argument = 0 + n;
ofstream textfile;
textfile.open ("textfile.txt");
textfile << argument << endl;
textfile.close();
++n;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15720 次 |
| 最近记录: |