首页 > 编程语言 > 详细

c++ 文件utf-8格式

时间:2015-06-03 15:28:48      阅读:162      评论:0      收藏:0      [点我收藏+]

 

#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() + 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;

}

 

c++ 文件utf-8格式

原文:http://www.cnblogs.com/ike_li/p/4549106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!