#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
string s;
cout << "creat str!" << endl;
fstream f("a.txt", ios::in|ios::binary);
if (!f)
{
cout << "open file faild" << endl;
return 1;
}
cout << "open file." << endl;
f.read((char*)&s, sizeof(s));
cout << "read."<< endl;
cout << s << endl;
return 0;
}
输出:
其他一切正常,其中a.txt内容:
就是输出不了string s的内容.请问是为啥?怎么改?