May 4th, 2010, 01:28 AM
Best non-MFC alternative to CString
I am working on an application that is non-MFC. I need to use variable types that can be accepted by LPCWSTR. Is there a non-MFC alternative to using CString? I searched around the net and this is what I think is the best alternative I found:
(1) Use wstring
(2) Convert wstring to LPCWSTR
Something like this code:
std::wstring s2ws(const std::string& s)
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring stemp = s2ws(myString);
LPCWSTR result = stemp.c_str();
Or are there any better alternatives besides this?
Also, if you know any good tutorial about the different kinds of strings in C++, please tell me also so that I know more about them.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!