开发者

Specifying the encoding when saving a file in a Windows app

开发者 https://www.devze.com 2023-02-16 23:37 出处:网络
I am writing a program that handles mostly Unicode text. The C standard library function \'fopen\' provides for writing the characters to file in utf-8 format by including in the mode string argument

I am writing a program that handles mostly Unicode text. The C standard library function 'fopen' provides for writing the characters to file in utf-8 format by including in the mode string argument "..., ccs=utf-8". It seems that the Windows API 'C开发者_JS百科reateFile' does give such provision. Must I use 'fopen' then?


This is Specific to programming under Windows, using Visual Studio, and Microsoft tools. My personal advice is to not to use fopen with the extended syntax, otherwise later there will be compatibility issues when porting your application to other operating systems. When under Windows, do the Windows way, use CreateFile.


The contents of the file are defined not by the file-opening function, but the actual data you write. After you get the file handle (either by fopen or CreateFile), you can write in UTF-8, or ANSI, or whatever you like.

Note that some encodings require a special bit at the beginning of the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消