需求:数据库数据格式为UTF-8,本地VS工程编码字符集为多字节字符集,导入到本地csv文件时需要转化多字节std::string为UTF-8 std::string
接口与实现:
1 #include <Windows.h> 2 #include <string> 3 4 //以下为main需要的头文件,接口实现不需要 5 #include <iostream> 6 #include <fstream> 7 using namespace std; 8 9 std::wstring MultiChartoWideChar(std::string str) 10 { 11 int nLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)(str.size()), NULL, 0); 12 WCHAR *pBuffer = new WCHAR[nLen + 1]; 13 MultiByteToWideChar(CP_ACP, 0, str.c_str(), (int)(str.size()), pBuffer, nLen); 14 pBuffer[nLen] = '