Convert CString to std::string and back

Flaviu_ 1,091 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++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
{count} votes

Your answer

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