2

Possible Duplicate:
How to convert CString and ::std::string ::std::wstring to each other?

Ok, I know my question may be trivial, but I have not yet found how I can convert an ATL::Cstring to a basic string. I have tried the "converting from CString example" of the page http://msdn.microsoft.com/en-us/library/ms235631%28v=vs.80%29.aspx but it does not work. Any due indication?

Community
  • 1
  • 1
arjacsoh
  • 8,932
  • 28
  • 106
  • 166

1 Answers1

7

This should work -

CStringA cstr1("Hello");
std::string str1(cstr1);

OR

CStringW cstr2(L"Hello");
std::wstring str2(cstr2);

CString is a macro that may be converted to CStringA or CStringW depending on whether UNICODE is defined or not.

Assigning CStringA to std::wstring and CStringW to std::string will not work, which is probably what is happening for you.

Superman
  • 3,027
  • 1
  • 15
  • 10