c++ 文件utf-8格式

#include <stdio.h>

  int i = 0;
 while (i < 20)
 {
    i++;
    WriteLog("d:\log.txt","aaaa中国人民");
 }

/utf-8格式
//WriteLog("d:\log.txt", "aaaa中国人民");
void WriteLog(char* file_path,string s)
{
    s = s + "
";//换行


    int len;
    int slength = (int)s.length() + 1;
    len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
    wchar_t* buf = new wchar_t[len];
    MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);


    
    FILE* fp = fopen(file_path, "a,ccs=UTF-8");

    fwrite(buf, sizeof(wchar_t), wcslen(buf), fp);


    fclose(fp);
    delete[]buf;

}
原文地址:https://www.cnblogs.com/ike_li/p/4549106.html