lundi 3 juillet 2017

Why does passing a std::string to CString.Format() only crash sometimes?

Using CString.Format(), I'm passing it a std::map that returns a std::string when given an int.

So:

CString cStr;
cStr.Format("%s", IntToStdStringMap[1]);

where IntToStdStringMap[1] returns some string, we'll say "Hello, World!". The issue is that this doesn't seem to crash every time. Eventually, I'll receive an access violation.

Why might this be?

Keep in mind, that changing the code to the following:

CString cStr;
cStr.Format("%s", IntToStdStringMap[1].c_str());

alleviates the issue.

Any ideas?

Aucun commentaire:

Enregistrer un commentaire