c++ 文件utf-8格式

时间:2024-12-23 08:33:43

#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 + "\r\n";//换行 int len;
int slength = (int)s.length() + ;
len = MultiByteToWideChar(CP_ACP, , s.c_str(), slength, , );
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, , 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; }