I have loads of c++ classes that reads data from a file stream. The functions looks like this.
bool LoadFromFile(class ifstream &file);
I'm creating a new function to read from memory instead of a file. So I googled around and a istringstream seems to do the trick without any modifications to the code.
bool LoadFromData(class istringstream &file);
Now my question is. I need to construct this stream to read from a char array. The string is not null-terminated, it's pure binary data and I got a integer with the size. I tried assigning it to a string and creating a stream from a string, however the string terminates after a null character.. and the data is copied.
int size;
char *data;
string s = *data;
How do I create a string from a char array pointer without copying the data + specifying the size of the pointer data? Do you know any other solution than a stringstream?