void CTCPDlg::OnButton2()
{ using namespace std;
char MY[100]={0};
CString str1;
CString str2;
string STR3 = "";
GetDlgItem(IDC_EDIT1)->GetWindowText(str1);
GetDlgItem(IDC_EDIT2)->GetWindowText(str2);
string STR1=(LPTSTR)(LPCTSTR)str1;
string STR2=(LPTSTR)(LPCTSTR)str2;//將CString 轉換成string
strcat(STR1,STR2);
}
有什么問題。。。
為什么
--------------------Configuration: TCP服務器程式 - Win32 Debug--------------------
Compiling...
TCP服務器程式Dlg.cpp
C:\Users\Administrator\Desktop\xin\TCP服務器程式\TCP服務器程式Dlg.cpp(274) : error C2664: 'strcat' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
執行 cl.exe 時出錯.
TCP服務器程式Dlg.obj - 1 error(s), 0 warning(s)
。。。。。。。。
uj5u.com熱心網友回復:
你想實作啥?strcat的引數是chart *的,你非要代入string變數,當然要報型別錯誤咯。uj5u.com熱心網友回復:
原型:extern char *strcat(char *dest,char *src);。函式回傳指標,兩個引數都是指標,第一個引數所指向的記憶體的地址必須能容納兩個字串連接后的大小。回傳指向dest的指標。strcat(STR1,STR2); 改成strcat(STR1.c_str();,STR2.c_str());
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/107121.html
標籤:基礎類
