|
CString->string
CString->std::string 例子:
CString strMfc="test";
std::string strStl;
strStl=strMfc.GetBuffer(0);
cfg.strServerIP = string((LPCTSTR)m_strAddr);
CString g_strIniName;
string strIniName = g_strIniName.GetBufferSetLength(g_strIniName.GetLength());
std::string->CString 例子:
CString strMfc;
std::string strStl="test";
strMfc=strStl.c_str();
int CStringToInt(CString str)
{
int nVal = atoi(str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
return nVal;
}
CString转char[]
char work_no[10];
Cstring m_csWorkno
memcpy(struResp.work_no,(LPCTSTR)m_csWorkno,m_csWorkno.GetLength());
string 转 char[]
strncpy_s(resWebConRes.mainAccount,strposTerminalNbr.c_str(),strposTerminalNbr.length());
CString转char*
char*pBuf=str.GetBuffer(0);
char*sz=str.GetBuffer(str.GetLength());
可以直接强制类型转换(LPTSTR)(LPCTSTR)str,即为char*类型
GetBuffer是返回一个锁定的内存地址,参数是指要锁定的内存长度
char转CString
CString str;
char a[]="121a";
str.Format(%s,a);
cout<<str<<endl;
char[] 转 string
char terminal_no[64]="";转string terminal_no
terminal_no = (string) terminal_no;
string strworkno(pworkno);
int -> char*
char DB_MyBusinessType[3]={0};//我平台业务类型 00-未知 01-支付费转话费
sprintf(DB_MyBusinessType,"%02d",struReq->nBusinessType) ;
--------------------string -> char*------------------------
string db_cfg_pwd_;
const_cast<char *>(db_cfg_pwd_.c_str())
|
|