std::string当我在将 a 转换为 a时偶然发现一个奇怪的行为时,我正在玩一些字符串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]...
我只是想知道是什么导致了这种奇怪的行为。
谢谢