ANSI编码方式转化为UTF-8方式
说明: 记事本txt有四种编码方式,分别为:UTF-8、ANSI、Unicode和Unicode big endian,当进行写操作,创建的txt编码格式,与写入汉字的编码方式相同;如果写入的汉字是不同的编码方式,此时创建的txt中,会出现乱码,所以需要把汉字转化为同一编码方式。 本文主要介绍:把汉字编码方式,由ANSI方式转化为UTF-8方式: 一、ANSI转化为UTF-8程序: [cpp] view plain copy print ? CString ToUTF8( const wchar_t * buffer, int len) //返回类型为CString { int size = ::WideCharToMultiByte(CP_UTF8, 0, buffer, len, NULL, 0, NULL, NULL); if (size == 0) return "" ; std::string newbuffer; newbuffer.resize(size); ::WideCharToMultiByte(CP_UTF8, 0, buffer, len, const_cast < char *>(newbuffer.c_str()), size, NULL, NULL); //如需返回string类型,直接 return newbuffer TCHAR outstr[64