이 바이너리 파일을 읽고 화면에 숫자를 인쇄하고 싶지만 이상한 문자가 인쇄됩니다. 이 바이너리 파일을 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;
}
다음과 같이하십시오 :'cout << (int) memblock [i] << endl;' – sgarizvi
@ sgar91 원시 데이터의 타입이'char' 인 경우에만 그렇게 할 것입니다. OP는 데이터 유형이 무엇인지에 대해 말하지 않았다. – paddy
메모리 누수를 막기 위해 [] memblock을 나중에 삭제하는 것을 잊지 마십시오 – Enigma