0

I have written the following statements:

   CString strResult;
   std::string errorReason("no this item");
   strResult.Format("the error reason is: %s", errorReason);

It seems that it could not format the std::string object correctly; However, if I just replace std::string as CStirng, then strResult could format correctly.

Why va_arg could support CStirng, instead of std::string?

Thanks

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
xinsong001
  • 81
  • 1
  • 6

1 Answers1

0

Unlike CString, std::string doesn't provide an implicit conversion to const char* (for good reasons) and, what is more important in this case, the binary layout of std::string may not be compatible with const char*. You should use errorReason.c_str() instead.

Community
  • 1
  • 1
vitaut
  • 49,672
  • 25
  • 199
  • 336