64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void print()
{
string name = "changsha";
ofstream outfile("my.txt",ios::binary);
outfile.write((char*)&name,sizeof(name));
outfile.close();
}
void scan()
{
string name;
ifstream infile("my.txt",ios::binary);
infile.read((char*)&name,sizeof(name));
cout << name << endl;;
infile.close();
}
int main()
{
//print();//写入
scan();//读取
return 0;
}
#include <fstream>
#include <string>
using namespace std;
void print()
{
string name = "changsha";
ofstream outfile("my.txt",ios::binary);
outfile.write((char*)&name,sizeof(name));
outfile.close();
string name1;
ifstream infile("my.txt",ios::binary);
infile.read((char*)&name1,sizeof(name1));
cout << name1 << endl;;
infile.close();
}
int main()
{
print();
return 0;
}
这样做就没问题了,,,求解决呀