// 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;}

评论