[RESOLVED] Reading binary file
Hey everybody,
Firstly, thanks for reading this thread. I'm c++ n00b so don't be too harsh on me :). Anyway I'm struggling to solve my first cpp project. Before I worked for a few month with .NET. So I reckon I have some basics, hopefully :D. Now to my problem.
So, I have a file from gps receiver. I can't specify exactly what type it is, but I suppose it's binary file. Definitely it's not a text :) and there many unreadable characters. Some of them are actually readable e.g. pair of identifiers for certain messages (µb=0xB5 0x62). After these identifiers there is a body with the message that has to be converted to whatever(int,long,double....).
I want to read sequentially the whole file from the start to the end (say it's around 150MB). Find these pair identifiers. Read the body of each identifier (with defined length ) to unique struct. I don't worry about the output for now. I would be glad if you can help me with the main loop. I have this for now:
Code:
void FileManager::openFile(){
//variables are located in FileManager.h
ifstream fp;
unsigned long len;
char *buf;
streambuf * pbuf;
char bufferA;
char bufferB;
fp.open("raw.ubx", ifstream::binary | ios::in);
fp.seekg(0, ios::end);
len = fp.tellg();
fp.seekg(0, ios::beg);
pbuf = fp.rdbuf();
while (pbuf->sgetc()!=EOF){
bufferB = pbuf->sbumpc();
if ((bufferB == 'µ') && (bufferA == 'b')){
/*function call of this identifier*/
}
bufferA = bufferB;
}
}
In my file on the first position there is µ character. But I get "-75" instead. All advices and tips from you are more than appreciated.
Also I would be glad if you know where to get offline ISO c++ documentation.
Thank you in advance :)