Click to See Complete Forum and Search --> : WCHAR to stl string
xargon
September 11th, 2003, 08:22 AM
Hi everyone,
How can I convert a WCHAR array to an STL string. I am using the FILE_NOTIFY_INFORMATION structure which has a WCHAR parameter as Filename (not null terminated) and a long as FileLength. Now I want to convert this WCHAR array to a STL string. Any suggestions on how to do it would be really appreciated.
Pankaj
Kheun
September 11th, 2003, 09:06 PM
Try the wstring for wchar_t version of STL string. There not need for conversion if you use this class.
xargon
September 14th, 2003, 06:18 PM
Hi,
I tried using the wstring function..However, I am still getting problems. of course, I am probablz using it completely wrong. If someone can help me, I would be extremely grateful.
I did a small tesy and have something like this. BTW: I am not using MFC
wstring test = L"ABS";
MessageBox (0, (const char *) test.c_str(), "", MB_OK);
No matter what I do, it always prints only the first letter in the message box...i.e A. I do not know much about these UNICODE strings. Any guidance on how I can convert them to normal C strings would be really great.
Thanks,
Xargon
P.S: Sorry for putting it in seperate post. my bad..cannot delete it :(
Mick
September 14th, 2003, 07:21 PM
If you are going to code in UNICODE then define _UNICODE in the preprocessor definintions.
If you are going to mix and match with MCBS then you need to convert back and forth, with conversion routines.
eg:
wstring test = L"ABS";
char* buff = new char[test.length()*2];
memset(buff,0,test.length()*2);
int i = wcstombs(buff,test.c_str(),test.length());
MessageBox (0, buff, "", MB_OK);
delete [] buff;
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.