您的位置:首页 > 编程语言 > C语言/C++

c++ CSTring TO string

2014-06-25 20:21 260 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: