fstream f;
f.open("E:\\test.dat",ios::in|ios::out|ios::binary);
f << 1;
for (int p = 0; p < 4; p ++ )
{
char j;
f.get(j);
char a[9];
a[8]='\0';
int n = 7;
int ch = 1<<31;
for ( int i = 0; i < 8; i ++ )
{
if ( ch & j) a[n--]='1';
else a[n--]='0';
ch >>= 1;
}
cout << a << endl;
}
上面这个程序,我预计的输出应该是
00000000
00000000
00000000
00000001
结果却是
11111111
11111111
11111111
11111111
f.open("E:\\test.dat",ios::in|ios::out|ios::binary);
f << 1;
for (int p = 0; p < 4; p ++ )
{
char j;
f.get(j);
char a[9];
a[8]='\0';
int n = 7;
int ch = 1<<31;
for ( int i = 0; i < 8; i ++ )
{
if ( ch & j) a[n--]='1';
else a[n--]='0';
ch >>= 1;
}
cout << a << endl;
}
上面这个程序,我预计的输出应该是
00000000
00000000
00000000
00000001
结果却是
11111111
11111111
11111111
11111111