I have to manually add a UTF-8 BOM to a simple text file. However, I'm not able to write the BOM with the following method. With my rather limited c++ knowledge I actually do not understand what I am doing wrong. I assume that it must be related to the fact that I only write 3 bytes - and the system expects me to write multiples of 2 for whatever reason. The code is compiled in Unicode Character set. Any hints pointing me to the correct direction would be welcome.
FILE* fStream;
errno_t e = _tfopen_s(&fStream, strExportFile, TEXT("wt,ccs=UTF-8")); //UTF-8
if (e != 0)
{
//Error Handling
return 0;
}
CStdioFile* fileo = new CStdioFile(fStream);
fileo->SeekToBegin();
//Write BOM
unsigned char bom[] = { 0xEF,0xBB,0xBF };
fileo->Write(bom,3);
fileo->Flush(); //BOOM: Assertion failed buffer_size % 2 == 0