标题:ofstream使用求助
取消只看楼主
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
结帖率:79.17%
 问题点数:0 回复次数:2 
ofstream使用求助
// VS2005 2008/8/24

#include <iomanip>
#include <fstream>
#include <iostream>
using namespace std;

struct data{
    unsigned type    :    2 ;
    unsigned d        :    1 ;
    unsigned context:    5 ;
};

void fprint(ofstream file,struct data t)
{
    int temp = (t.type<<6) + (t.d<<5) + t.context;
    if (temp<16)
    {
        file<<hex<<0 ;
    }
    file<<hex<<temp<<endl ;
}

int main(void)
{
    int j;
    ofstream fsOut("TestData.dat");
    
    for(j=0;j<16;j++)
    {
        int j1=(j&8)&&1,j2=(j&4)&&1,j3=(j&2)&&1,j4=j&&1;
        fsOut<<hex<<j<<" "<<j<<" "<<dec<<1<<endl ;
    }

    struct data t;
    t.type = 2;
    t.d = 0;
    t.context = 0x12;
    fprint(fsOut,t);
    fsOut.close();
    cout<<hex<<0x12<<endl ;
    return 0;
}

上面得子函数 fprint()定义的由什么问题呢 ?
为什么运行的时候出现这个错误
但是的哦dos窗口能输出 12 ,说明这个错误发生在 cout<<hex<<0x12<<endl ;语句之后,
而这个语句之后只有个return

error.JPG (23.22 KB)
搜索更多相关主题的帖子: fstream 结构体 错误 
2008-08-31 00:02
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
得分:0 
回复 2# 随心 的帖子
谢谢,还确实如此
2008-08-31 08:08
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
得分:0 
回复 5# blueboy82006 的帖子
project-->setting-->c/c++中
2008-08-31 09:37



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




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

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