I want to get a file and store it in a character array. The file isn't ASCII formatted so I can't use strlen(). Is there any other way to get the size of the array?
Printable View
I want to get a file and store it in a character array. The file isn't ASCII formatted so I can't use strlen(). Is there any other way to get the size of the array?
you haven't told what format is .UTF8 ? UCS2 ? there should be some corresponding functions to get the length .
If you're treating the file as one big chunk of data, just use fstream's methods to get the size before you read it.
Code:std::ifstream file("somefile.dat", std:ios::binary);
std::vector<char> buffer;
file.seekg(0, std::ios::end);
buffer.resize(file.tellg());
file.seekg(0, std::ios::beg);
file.read(&buffer[0], buffer.size());
...