Reputation:
I am trying to get a substring from a CString
using C++. For that I am using strstr
function. But it is not working at al
CString str = m_sectionDataList->GetNext(pos);
char* chToMatch = (char*)(LPCTSTR)str;
char *match = "=";
//char * sMatched = strstr(ch, match);
if (strstr(match, chToMatch) != NULL) {
MessageBox(NULL, str, L"Done", 1);
}
Upvotes: 0
Views: 522
Reputation:
Finally I've found it. Need to use a macro of C++ and you will found it converted.
CT2A ascii(str, CP_UTF8);
now you can just access it using ascii.m_psz and its buffer also.
Upvotes: 0
Reputation: 5930
You are passing arguments in the incorrect order. strstr
expects first argument to be scanned string, and second should be a match. Right now you are searching your target string in the one byte =
template, which will most certainly fail.
Upvotes: 1