You can read a file's contents into a char
array using the following function:
void readFileContentsIntoCharArray(char* charArray, size_t sizeOfArray) {
std::ifstream inputFileStream;
inputFileStream.read(charArray, sizeOfArray);
}
Now the file is written in UTF-16LE, so I want to read the file's contents into a char16_t
array in order to process it more easily later on. I tried the following code.
void readUTF16FileContentsIntoChar16Array(char16_t* char16Array, size_t sizeOfArray) {
std::ifstream inputFileStream;
inputFileStream.read(char16Array, sizeOfArray);
}
Ofcourse it didn't work. std::ifstream
doesn't accept char16_t
. I've been searching for a solution for a long time, but the only relevant one I've found so far is https://stackoverflow.com/a/10504278/1031769, which doesn't help because it uses wchar_t
instead of char16_t
.
How to make it work with char16_t
?