-
May 4th, 2010, 12:28 AM
#1
Best non-MFC alternative to CString
Hi all,
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 len;
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 r(buf);
delete[] buf;
return r;
}
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.
Thank you!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|