c++ CSTring TO string

来源:互联网 发布:cmd mac地址 编辑:程序博客网 时间:2024/05/19 08:38
1.<pre id="answer-content-788564172" accuse="aContent" class="answer-text mb-10" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); font-size: 14px; line-height: 24px; background-color: rgb(255, 255, 255);">string 是 语言的东西 是c++语言的CString 是VC++ IDE内嵌的,是MFC的不是一个概念CString 离开VC++不能用string  在任何支持C++的IDE中都能用
bool CMysqlHandle::CStringToString(CString &myCSting,string &mystring){mystring.clear();CStringA stra(myCSting.GetBuffer(0));myCSting.ReleaseBuffer();mystring = stra.GetBuffer(0);stra.ReleaseBuffer();return true;}


2.

wstring是宽char,Unicode编码,一般情况下一个字符占两个字节大小string是窄char,AscII编码,一个字符占一个字节大小

bool CMysqlHandle::StringToWString(string &str,wstring &wstr){int nLen = (int)str.length();    wstr.resize(nLen,L' ');int nResult = MultiByteToWideChar(CP_ACP,0,(LPCSTR)str.c_str(),nLen,(LPWSTR)wstr.c_str(),nLen);if (nResult == 0){  return FALSE;}return TRUE;}

3.Cstring 转lpctstr

直接转即可

CString strTemp;

CFile tf(strTemp, CFile::modeRead | CFile::shareDenyWrite | CFile::typeBinary);

0 0
原创粉丝点击