标题:文件为乱码输出
取消只看楼主
wx1144542900
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2013-11-1
结帖率:100%
 问题点数:0 回复次数:0 
文件为乱码输出
程序代码:
#include <fstream>
#include <iostream>
using namespace std;
struct student 
{
    char name[20];
    int num;
    int age;
    char sex;
};

int main()
{
    student stud[3]={"li",1001,18,'f',"fun",1002,19,'m',"wang",1003,17,'f'};
    ofstream outfile("example.txt",ios::binary);
    if(!outfile)
    {
        cout<<"open error!"<<endl;
        return 1;
    }
    for(int i=0;i<3;i++)
        outfile.write((char *)&stud[i],sizeof(stud[i]));
    outfile.close();
    return 0;

}


用的VC,与编译器有没有关系?
搜索更多相关主题的帖子: color 
2013-12-21 19:17



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




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

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