正文

ofstream 对象的使用注意点2008-08-31 09:12:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/37983.html

分享到:

// VS6 2008/8/30

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

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

// ofstream 对象不能复制,只能引用传参
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;
}

阅读(2601) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册