【发布时间】:2016-11-12 17:23:12
【问题描述】:
请帮忙,代码执行输出而不是
123456
只是
456
为什么在写入之前清除文件?未设置截断
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream a{ "1.txt",ios_base::ate };
a << "123";
a.close();
ofstream b{ "1.txt",ios_base::ate };
b << "456";
b.close();
ifstream c{ "1.txt" };
string str;
c >> str;
cout << str;
return 0;
}
【问题讨论】:
-
文件每次都重写
-
只需阅读您使用的功能的文档。文档非常清楚他们的工作。 -1
标签: c++