Convert CString to std::string and back

Flaviu_ 1,031 Reputation points
2022-04-25T12:56:56.157+00:00

I have the following string (got from an method):

ÉÛ3òBc ß™ î²íÈ. Á:˜"´ÑÌç°A×üí„2 91Nÿ   

This is not quite ASCII, I am aware of that.

196118-untitled.png

196110-untitled2.png
196119-untitled3.png

Now, If I convert it as CString:

CString s1(dec.c_str(), dec.size());  

and then convert back:

std::string t1 = CStringA(s1);  

I got:

TRACE("%d|%d|%d\n", dec.size(), s1.GetLength(), t1.size());  

80|80|37

which is not the same. My question is: how can convert this strange std::string dec to CString and then back in order to get it back exactly the same ?

Developer technologies C++
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.