windows下读取utf-8文件
#include <stdio.h> #include <tchar.h> #include <memory> int main() { FILE* fp1 = fopen("E:\\11111111\\20140104.bad", "r,ccs=UTF-8"); // 不用css时使用文件原有编码 //setlocale(LC_ALL, "chs"); FILE* fp3= fopen("test.txt", "w,ccs=UTF-8"); // 不指定css时使用原有数据编码,如果需要可以通过修改文件头(utf-8无bom -> utf-8 bom) wchar_t * buffer = new wchar_t[1024]; //fgetws(buffer,3,fp1); while(!feof(fp1)) { if(fgetws(buffer, 1024, fp1)) { fputws(buffer,fp3); //fputws(buffer,stdout); memset(buffer,0,sizeof(buffer)); } } delete []buffer; fclose(fp1); fclose(fp3); getchar(); return 0; }
http://www.cplusplus.com/reference/cwchar/fgetws/
http://blog.csdn.net/zollty/article/details/6771858
https://msdn.microsoft.com/en-us/library/yeby3zcb.aspx
http://www.cnblogs.com/chenwenbiao/archive/2011/07/27/2118372.html