I was playing with some strings when I stumbled upon a weird behavior while converting a std::string
to a LPCSTR
.
I have written a small test application to demonstrate :
#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;
}
And here is the output :
some text in addition with this other text
some text in addition with this other text
îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ...[more unreadable stuff]...
I am simply wondering what is causing this strange behavior.
Thank you