标题:二进制文件读写
取消只看楼主
王翔
Rank: 2
等 级:论坛游民
帖 子:13
专家分:12
注 册:2015-2-1
结帖率:50%
已结贴  问题点数:10 回复次数:1 
二进制文件读写
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
    string s;
    ifstream fin("Rata.txt");   //  内容为  3 1 2
    ofstream fout;
    if(fin.fail())
        cout<<"error";
    getline(fin,s);
    fin.close();
    cout<<s<<endl;

    fout.open("Data.dat",ios::binary|ios::in);
    fout.write((char *)&s,sizeof(s));
    fout.close();


    string temp;
    fin.open("Data.dat",ios::binary);
    fin.read((char *)&temp,sizeof(s));
    cout<<temp;

    return 0;
}

调试时访问内存访问冲突。
搜索更多相关主题的帖子: include return 二进制 
2015-03-19 20:53
王翔
Rank: 2
等 级:论坛游民
帖 子:13
专家分:12
注 册:2015-2-1
得分:0 
回复 2楼 rjsp
上一个为什么会出错啊  
2015-03-20 10:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-442833-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.115447 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved