问题
I need some help. I'm writing a program that opens 2 source files in UTF-8 encoding without BOM. The first contains English text and some other information, including ID. The second contains only string ID and translation. The program changes every string from the first file by replacing English chars to Russian translation from the second one and writes these strings to output file. Everything seems to be ok, but there is BOM appears in destination file. And i want to create file without BOM, like source. I open files with fopen function in text mode with ccs=UTF-8 read string with fgetws function to wchar_t buffer and write with fputws function to output file
回答1:
Don't use text mode, don't use the MS ccs=
extension to fopen
, and don't use fputws
. Instead use fopen
in binary mode and write the correct UTF-8 yourself.
来源:https://stackoverflow.com/questions/36253308/is-it-possible-to-prevent-adding-bom-to-output-utf-8-file-visual-studio-2005