Hi I am getting a conversion error Code: CString Instring; CString Automesg[2]; Automesg[0]="test 1"; Automesg[1]="Test Example2"; if(strcmp(Instring,Automesg[0])==0) //HERE IS THE ERROR FOR InString Variable { Sleep(1000); } [B]error C2664: 'strcmp' : cannot convert parameter 1 from 'CString' to 'const char *' [/B] Can anyone resolve it
You can use the "compare" function. Say, you have 2 CStrings StringA and StringB. You can compare them like : Code: if ( StringA.compare(StringB) == 0 ) cout << StringA << " and " << StringB << " are not equal."; So, your code can be modified as : Code: CString Instring; CString Automesg[2]; Automesg[0]="test 1"; Automesg[1]="Test Example2"; if(Instring.compare(Automesg[0])==0) { Sleep(1000); }
I think the problem is likely a UNICODE issue. With UNICODE enabled in your project, CStrings default to "wide" character strings. A "wide" character is 2 bytes whereas normal char is 1 byte. You can use the "wide" versions of the comparison functions, wcscmp() v. strcmp(), or to keep everything portable, use the TCHAR macros. _tcscmp() is a macro that will evaluate to strcmp() in MCBS builds or wcscmp() in UNICODE builds.