Hello,
I have a problem in reading p5 PGM file:
ifstream::pos_type _Start, _End, _Size;
ifstream::off_type _newStart;
char * memblock;
vector<vector<int> > initMatrix ;
std::ifstream inf;
inf.open("a.pmg", ios_base::in | ios_base::binary);
if (inf) {
std::string line;
for (int i = 0; i<3 ;i++)//skip the first 3 lines that contain the info
{
std::getline(inf, line);
}
_Start = inf.tellg();//starting point just after those 3 lines
inf.seekg (0, ios::end);
_End = inf.tellg();
_Size = (_End - _Start);
cout<<_Size;//size of the data in the file without the first three lines
memblock = new char [_Size];
_newStart = (ifstream::off_type) _Start;//casting _Start to off_type to be passes as offset, to start reading the file after the first three lines, idon't know if that idea is right or not
inf.seekg (_newStart, ios::beg);
inf.read (memblock, _Size); // 1st prob., nothing will be red
cout<<memblock; // nothing in the o/p
////////////////////////////////////////////////////////////////////////////
//this second part is not connected directly to the code but I want to split the data in the memblock which is a matrix of 1024*1024 and push the data into a vector of vectors like so
//this code is right if we are dealing with ASKII file and I have no clue how to make the same idea on the previous problem
while (std::getline(inf, line)) {
initMatrix.push_back(vector<int>());
// Break down the row into column values
std::stringstream split(line);
int value;
while (split >> value){
initMatrix.back().push_back(value);
}
}
}
inf.close();
close