私は最初のMFCアプリケーション内に単純なメッセージを表示しようとしています。MFC - メッセージを表示
不思議なことに、最初のサンプルが正しく動作せず、2番目のサンプルが正しく動作します。
auto text = std::to_wstring(1).c_str();
MessageBox(text, NULL, 0); // Not ok, the message is empty
auto temp = std::to_wstring(1);
MessageBox(temp.c_str(), NULL, 0); // Ok, display 1
この現象はなぜ説明できますか?
[std :: string :: c \ _str()とtemporaries]の複製があります(http://stackoverflow.com/questions/10006891/stdstringc-str-and-temporaries) – IInspectable