1) I am trying to open a binary file.
2) With a pointer value, I am trying to read the value in memory set by the pointer. But the first value I get I want to start the pointer from 0 to a specified location.
3) I want to get that value in memory and be able to use it (i.e. int, double) so I can do math with it!!
4) I'm having trouble!!!! HELP!!!!!
Code:
fstream data;
data.open(filename, ios::in |ios::out | ios::binary);
if(!data.is_open())
{
cout << "Error opening file. Please try again." << endl;
exit(1);
}
ptr5 = user_def_beg_pix_ptr = (given_line - 1)*numsamples + (given_col - 1);
ptr1 = ptr2 - 1;
ptr2 = ptr5 - numsamples;
ptr3 = ptr2 + 1;
ptr4 = ptr5 - 1;
ptr6 = ptr5 + 1;
ptr7 = ptr8 - 1;
ptr8 = ptr5 + numsamples;
ptr9 = ptr8 +1;
ptr5 = ptr5*sizeof(float);
ptr6 = ptr6*sizeof(float);
ptr4 = ptr4*sizeof(float);
//here's the important part giving me trouble
data.seekg(0,ios::beg);
size = data.tellg();
cout<< "This is the first size:" << size << endl;
value[0] = 0; //clearing first array just to test things.
value[1] = 0;
value[2] = 0;
//may erase things later
data.seekg(ptr1, ios::beg);
size = data.tellg();
cout<< "this is the second size: " << size << endl;
data.write((char*) &value, sizeof value);
data.read((char*) &value, sizeof value);
cout << value[0] << " -next value- " << value[1]
<< " -next value- " << value[2] << endl;
Output:
This is the first size:-1
this is the second size: -1
0 -next value- 0 -next value- 0
this is what's in ptr 96876
This is the pixel val 5: 96876
96872
96880