64,686
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str;
ofstream out("result01", ios_base::binary);
out << "result01";
out.close();
ifstream in("result01", ios_base::binary);
in >> str; //可以读出
cout << "1--" << str << endl;
str = "";
in >> str; //没东西可读
cout << "2--" << str << endl;
in.clear();
in.seekg(0, ios_base::beg);
str = "";
in >> str; //又可以读出
cout << "3--" << str << endl;
in.close();
}
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str;
ifstream in("result01", ios_base::binary);
in >> str;
cout << "1--" << str << endl;
str = "";
in >> str;
cout << "2--" << str << endl;
in.clear();
in.seekg(0, ios_base::beg);
str = "";
in >> str;
cout << "3--" << str << endl;
in.close();
}