Is it possible to prevent adding BOM to output UTF-8 file? (Visual Studio 2005)

半城伤御伤魂 提交于 2020-01-06 03:16:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!