I have a program I that looks like C-style programming and want to re-write it using STL stuff like vectors or strings. The function in question is a file loader. There is an array of chars being made, this is referenced by two pointers a char* and a cast unsigned char*. This made me think: is it possible to have two std::vectors/std::arrays share the same data?
On another note, how to go about loading (std::fread) the file without using `new[]`, keeping in mind how the data will used later. I found a vector<char> not good for string comparisons, maybe a string s(2048)?
Code:
std::FILE* nfile = fopen(filename,"rb");
char *const header = new char[2048];
*header = 0; //dunno why they initialize first char...
const unsigned char *const uheader = (unsigned char*)header;
const unsigned int siz = (unsigned int)std::fread(header,2048,1,nfile); // Read first 2048 bytes.
//...code goes on to compare the header and uheader with string literals and hexadecimal numbers respectively
just using 2 vectors for char and unsigned char I'd end up with 2 copies of the header data.