I am trying to work with a bmp file in linux with g++ compiler. I am using C++ language.
I Need to load a .bmp file from the standard input. for example:
./a.out < test.bmp
So I need a Code to do this job. I think storing the whole .bmp file is good by I don’t know how to do this.
I Tried this code but it didn’t Work:
vector<int> bitmap; int b; while ( cin >> b ) { bitmap.push_back(b); cout << "!" << endl; }
So How should I Do this?
Advertisement
Answer
I Found an answer That Works Correctly. This Code Reads The bmp_info_header from the *.bmp file from the standard input:
char bmpHeader[54]; cin.get(bmpHeader, 54);
the “54” in cin.get() tells the system to accept the max 54 numbers from the input and ignores the other.
now for example if we want to find the *.bmp size we should use this code:
int filesize = *((int*)(headers + 2));