.bmp 画像を開き、それを 2D 配列に入れることができる C++ プログラムを作成しています。今、私は次のようなコードを持っています:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "Image.h"
using namespace std;
struct colour{
int red;
int green;
int blue;
};
Image::Image(string location){
fstream stream;
string tempStr;
stringstream strstr;
stream.open(location);
string completeStr;
while(!stream.eof()){
getline(stream, tempStr);
completeStr.append(tempStr);
}
cout << endl << completeStr;
Image::length = completeStr[0x13]*256 + completeStr[0x12];
Image::width = completeStr[0x17]*256 + completeStr[0x16];
cout << Image::length;
cout << Image::width;
cout << completeStr.length();
int hexInt;
int x = 0x36;
while(x < completeStr.length()){
strstr << noskipws << completeStr[x];
cout << x << ": ";
hexInt = strstr.get();
cout << hex << hexInt << " ";
if((x + 1)%3 == 0){
cout << endl;
}
x++;
}
}
256x256 のテスト ファイルでこれを実行すると、0x36E に到達してエラーが発生し、それ以上進まなくなるまで正常に印刷されます。これは、completeStr文字列が bmp ファイル内のすべてのデータを受信していないために発生します。bmp ファイルのすべての行を読み取れないのはなぜですか?