1. convet char * To cstring
Code:
Char * P = "just only test ";
Cstring STR = P;
Compile the aboveCodeThe following error is prompted:
ERrorC2440: 'initializing': cannot convert from 'Char * 'to 'atl: cstringt <basetype, stringtraits>'
SolutionJueMethod:
(1) UseThe multibytetowidechar function first converts string encoding to unicode encoding, and then assigns a value to the cstring object.
Char * pstr = "just only test"; <br/> cstring STR; <br/> int nlenth = multibytetowidechar (cp_acp, mb_composite, P,-1, null, 0 ); <br/> tchar * pwstr = new tchar [nlenth]; <br/> multibytetowidechar (cp_acp, mb_composite, P,-1, Q, nlenth ); <br/> STR = Q; <br/> Delete Q; </P> <p>
(2) Use the w2a macro
Uses_conversion; <br/> char * pstr = "just only test"; <br/> cstring STR = a2w (pstr); <br/>
Multibytetowidechar ()
Function: maps a string to a unicode string. The string mapped by this function does not need to be a multi-byte character group.
Function prototype: int multibytetowidechar (uint codePage, DWORD dwflags, lpcstr lpmultibytestr, int cchmultibyte,
Lpwstr lpwidecharstr, int cchwidechar );