我想读取这个二进制文件并在屏幕上打印数字,但它正在打印奇怪的字符。我从 MATLAB 生成了这个二进制文件。如何正确显示数据?
#include <iostream>
#include <fstream>
using namespace std;
ifstream::pos_type size;
char * memblock;
int main ()
{
ifstream file ("seg.bin", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = (int)file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
cout << "the complete file content is in memory";
for (int i=0;i<size;i++)
{
cout<<memblock[i]<<endl;
}
}
else cout << "Unable to open file";
return 0;
}