想做Dog的Monkey~
2021-01-15 20:30c++,为什么文件读取进string失败,并且主函数返回值异常?
#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的内容.请问是为啥?怎么改?
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- java(JNA/JNative/JNI等)怎样调用 DLL 中 返回 指针 的函数 得到指针值?
- 企业应用
- 0个回答
- 这个函数有什么问题,一调用就中断
- c++
- vector
- 3个回答