The first problem seems to be how your example strings are printed out.
There are parts with control code abbreviations enclosed by parentheses (see
Control character - Wikipedia[
^]). So it might be that these are placeholders created by the print function.
{RS}
for example might be a place holder for the control code 0x1E (RS = Record Separator).
So you have to check first if your
std::string
really contains
{RS}
or the byte 0x1E. To check this print the hex code for the first letters.
I assume that I'm right because that would explain why the
CString
is printed in a different way.
The next check would be printing out the hex values from the
CString
. They might be the same as for the
std::string
. Then there was only a problem with the output but not with the assignment.
As already mentioned by CPallini in the comments you might also get problems with Unicode builds. To avoid this you should use
CStringA
instead of
CString
if the strings contain only ASCII characters (codes less than 0x80):
CStringA str = a_strdata.c_str();
If the
CStringA
is still not the same as the
std::string
check if there are NULL bytes in the input string. If so, you can't use
CString
. Then you have to use a binary buffer.
A simple check:
CStringA str = a_strdata.c_str();
for (int i = 0; i < str.GetLength(); i++)
printf("%02X %02X\n", a_strdata.at(i), str.GetAt(i));