I have been working now on a project based on DirectX and I am struggling with something. Though the DirectX SDK relies heavily on Windows data types like LPSTR, LPCSTR, … I have been using for my own classes std::string which was quite easy to work with, but it looks strange to mix both ways of handling strings. Although this is a vague question, what do you suggest – should I work with the strings or with the Windows pointers for different string types to keep some consistency?
I have been working now on a project based on DirectX and I am
Share
LPSTRis just an alias forchar*andLCPSTRis an alias forconst char*, so your question actually sounds like “Should I use C++ strings or C strings?”Well, C++
std::stringhas a member function calledc_str()(or the equivalentdata()function for STL compatibility) that returns a (non-modifiable) C string. So any time a function accepts anLPCTSTR, you can provide the output ofc_str()as an argument.I suggest you working with C++
std::stringwhenever you can, it is safer.