I tried this in c++:
std::string teststring = "hello";
MessageBox(NULL,teststring,NULL, NULL);
error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'std::string' to 'LPCSTR'
I tried this in c++:
std::string teststring = "hello";
MessageBox(NULL,teststring,NULL, NULL);
error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'std::string' to 'LPCSTR'
First, it looks like Visual C++ so tag it properly.
You can get the inside buffer using c_str() method on a std::string, so your code becomes:
std::string teststring = "hello";
MessageBox(NULL,teststring.c_str(),NULL, NULL);
MessageBox's second and third parameter expect a C string.
To get a C string from a std::string you call c_str(), therefor the correct way to call it is:
std::string teststring = "hello";
MessageBox(NULL, teststring.c_str(), NULL, NULL);
what about try this?
std::string teststring = "hello";
LPCSTR tmp = teststring .c_str()
MessageBox(NULL,tmp ,NULL, NULL);