0

私はこれをC ++で試しました:

std::string teststring = "hello";
MessageBox(NULL,teststring,NULL, NULL);

エラー C2664: 'MessageBoxA': パラメーター 2 を 'std::string' から 'LPCSTR' に変換できません

4

3 に答える 3

1

MessageBox の2 番目と 3 番目のパラメーターは、 C の stringを想定しています。

std:: string から C 文字列を取得するには、c_str()を呼び出します。したがって、正しい呼び出し方法は次のとおりです。

std::string teststring = "hello";
MessageBox(NULL, teststring.c_str(), NULL, NULL);
于 2013-09-19T12:03:35.650 に答える