から への変換中に奇妙な動作に遭遇したとき、私はいくつかの文字列で遊んでいstd::string
ましたLPCSTR
。
デモ用に小さなテスト アプリケーションを作成しました。
#include <string>
#include <Windows.h>
#include <iostream>
using namespace std;
int main ()
{
string stringTest = (string("some text") + " in addition with this other text").c_str();
LPCSTR lpstrTest= stringTest.c_str();
cout << lpcstrTest << '\n';
cout << (string("some text") + " in addition with this other text").c_str() << '\n';
LPCSTR otherLPCSTR= (string("some text") + " in addition with this other text").c_str();
cout << otherLPSTR;
}
そして、ここに出力があります:
some text in addition with this other text
some text in addition with this other text
îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ...[more unreadable stuff]...
この奇妙な動作の原因は何なのか、ただただ疑問に思っています。
ありがとうございました