网上找了一个转换 字符串的方法
string GBKToUTF8(std::string& strGBK) { string strOutUTF8 = ""; wchar_t * str1; int n = MultiByteToWideChar(CP_ACP,strGBK.c_str(),-1,NULL,0); str1 = new WCHAR[n]; MultiByteToWideChar(CP_ACP,str1,n); n = WideCharToMultiByte(CP_UTF8,NULL); char * str2 = new char[n]; WideCharToMultiByte(CP_UTF8,str2,n,NULL); strOutUTF8 = str2; delete[]str1; str1 = NULL; delete[]str2; str2 = NULL; return strOutUTF8; }
在提交到数据库操作时用这个方法转换一下就可保存成中文了
void insert() { otl_stream o(50,"insert into test_tab values(:f1<int>,:f2<char[31]>)",db ); char tmp[32]; string tt="姓名bhgy765_+00"; string ts=GBKToUTF8(tt); strcpy(tmp,ts.c_str()); o<<1<<tmp; }