我把一个evc4程序在VS2005中转换,但在2005下面报错,不知道是哪里的设置问题,大家帮忙看下:
CString str1;
str1.Format(L"insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,'"+tempname+"')",Iputid,drankid,pose,v1,price);
tempname是CString类型,这个地方报错:
error C2679: binary '+' : no operator found which takes a right-hand operand of type 'const char [3]' (or there is no acceptable conversion)
我把它改为%s插入,没有报错,但是程序运行错误
CString str1;
str1.Format(L"insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,'"+tempname+"')",Iputid,drankid,pose,v1,price);
tempname是CString类型,这个地方报错:
error C2679: binary '+' : no operator found which takes a right-hand operand of type 'const char [3]' (or there is no acceptable conversion)
我把它改为%s插入,没有报错,但是程序运行错误
CString s1( "abc" );
CString s2( "def" );
ASSERT( (s1 + s2 ) == "abcdef" );
CString s3;
s3 = CString( "abc" ) + "def" ; // Correct
s3 = "abc" + "def";
// Wrong! The first argument must be a CString.
试试这样。
CString str1(_T(""));
str1.Format(_T("insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,\'%s\')"), Iputid,drankid,pose,v1,price,tempname);
AfxMessageBox(str1);