UTF16 File Replication Help

I exported a file from an application. It exported as a CSV. I opened it in notepad and copied the info into my C++ file manipulation program. I read another data file and then do a bunch of manipulation to create my own export files that i can re-import into the original application. My file manipulation works flawlessly except;

I noticed the original export file is twice as large.
When running file compare programs it says the original file is a binary so it can't make a comparison against my file.
I downloaded a hex editor and found that in the original file every other character is a '.' aka '00'.
I found a format byte at the beginning of the file. I think its for UTF 16.
'ÿþ' aka 'FF FE'.

How do i need to modify my c++ export creator program to output into this format?

Will i have to output the '.' every other character manually or is that built into the formatting and is done automatically?

Thanks for all the help.
I made a sloppy solution (that i understand at least). I created a function to expedite things somewhat. This will only work on certain OS's as sizeof(wchar_t) is dependent on this.

You will typically recognize a UTF16 file by looking at it in hex. The first 2 bytes should be FF FE. If you don't use any special characters then every other byte will be 00 which will also be an indicator that you have a 2byte UTF16 file.

Warning! I am not an official nor educated in any of this. This is me stumbling through it and hoping to help the next guy.

Ex.
//First 2 bytes needs to be byte mark aka BOM for UTF16
ofile4 << "ÿþ"; //or FF FE

UTF16((wstring) L"Your text here to be outputted as UTF16",ofile4); UTF16((wstring) L"\15\12",ofile4);
//\15\12 is your newline in UTF16 which is 0D 00 0A 00 in hex
UTF16((wstring) L"\15\12",ofile4);
//and on and on

void UTF16(wstring TheString, ostream& OutputFile ) //void writeData(ostream& dataOut);
{
OutputFile.write((char *) TheString.c_str(), TheString.length() * sizeof(wchar_t));
}


Thanks for the help ME!
Last edited on
Topic archived. No new replies allowed.