I'm stuck in something that maybe some of you consider pretty simple, but i'm not really an expert in c++, so i will explain a little bit what i want to do and where is my problem:
- I opened a raw image file and buffered in memory. With the buffered data i pretend to make calculations with the binary data, and here is when the problem arise: to open the file and charge it in memory i use char*, but for manipulations i pretend to use double* variables.
Does anyone can point me in the right direction in order to convert the file in memory from char* to double*?
Here what i have done until now:
#include <fstream>
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
fstream::pos_type size;
double* x;
char* y;
int main(int i, char *img[]) // i is a counter, img the name of the file
{
i=1;
// Opening the file
ifstream file (img[i], ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg(); // knowing the size of the file
y = new char [size]; // changing the size in the buffer
file.seekg (0, ios::beg); // repositioning pointer in the begining
file.read (y, size); // reading the file, loading to "y"
file.close(); // closing file
// here is what i want to do, but i don't know how: assign from char* to double*
for (i=0; i<size; i++) { x[i] = y[i]; }
// Obviously what is above is wrong, i just leave it as a reference
// here i will call a future external function for calculations with the data
futurefun(x,size);
// cleaning the mess
delete[] x;
delete[] y;
}
else cout << "Unable to open file";
return 0;
}
I tried using:
for (i=0; i<size; i++) { x[i] = atof(y[i]); }
and also:
for (i=0; i<size; i++) { stringstream(y[i]) >> x[i]; }
but didn't work.
Any comments or ideas i will really appreciate.

New Topic/Question
Reply
MultiQuote















|