使用C++
,我正在尝试从如下所示的文件中读取:
111111100100000000001101
100011100000000000000000
111111000100000000101001
001011110100000000000011
001111000100000000000110
每行代表 3 个字节,我想使用uint8_t
.
我写了这段代码,在 while 循环中,为了简单起见,我只取每一行的第一个字节:
uint8_t * buffer = new uint8_t[lSize];
memset(buffer, 0, lSize);
ifstream file(argv[1]);
string str;
int i=0;
while(getline(file, str)){
string byte = str.substr(0,8);
bitset<8> bitsaddress(byte);
int number = bitsaddress.to_ulong();
buffer[i]=number;
cout << buffer[i]<<endl;
i++;
}
但是shell上的输出是这样的:
-
�
�
'
-
e
N
k
如果我打印变量number
而不是buffer[i]
我有正确的行为。
我不明白为什么会发生这种情况,有人可以解释吗?