当前位置:网站首页>Mutual conversion of CString and char*

Mutual conversion of CString and char*

2022-06-25 21:13:00 Rabbit cloud program

CString yes windows String , Sometimes its conversion makes people gnash their teeth , quite a lot MFC All of the interfaces involved in string conversion , Even more hateful is the conversion of byte encoding , All two lead to a variety of situations , Novice may succeed in conversion today , Next time the same method fails to convert , And many MFC The interface is hard to output correct results if the string input is wrong .

Unicode Next CString Convert to char *

CString convert to char* There are many ways , Here are three common

 picture

But this is limited to wide bytes Unicode The situation of , Not in the case of narrow bytes and multi bytes , Therefore, in general, multi byte encoding conversion is also involved , This is a headache . In general ,Unicode To convert to multiple bytes, you can use the following methods

 picture

Smart you'll find , This involves copying memory , And the calculation of string length , In particular, the last character should be assigned as 0. This is the way to success . So it can be summarized as the following steps

 picture

Of course, there are faster and simpler ways , That's using T2A,W2A, These two simple functions are artifacts , Can easily help you complete

原网站

版权声明
本文为[Rabbit cloud program]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202181333005771.html