wcstok,strtok memory corruption

CString mystring("ob_jw_ay");

CString anotherstring ;

anotherstring =mystring;//memory corruption!!!

TCHAR* string = (TCHAR*)(LPCTSTR)mystring;
TCHAR seps[] = "_";
TCHAR* token;

token = strtok( string, seps );

while( token != NULL )
token = strtok( NULL, seps );

//Now both strings will be changed.Because both CString::m_pchData are pointing to the same memory and strok/wcstok changes it. If you want 'anotherstring' to remain unchanged do
anotherstring +=mystring;


Popular posts from this blog

Long running Java process resource consumption monitoring , leak detection and GC tuning

OpenLayers Advanced Clustering and Setting dynamic images for OpenLayer Styles via Ajax

Java Script Development Guidlines