Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert CString to string in Unicode environment 1

Status
Not open for further replies.

titanandrews

Programmer
Feb 27, 2003
130
US
Hi,
Does anyone know of an easy way to convert a CString to a string in a Unicode environment? The following code is what I used to use, but now I need my app to be Unicode (#define _UNICODE) and my function no longer works. Any suggestions on how to do this in a safe and efficient manner?


Code:
string toStlString(const CString& aString)
{
    char *tmpStr = new char[(aString.GetLength() + 1];    
    strcpy(tmpStr,aString);
    string myString = tmpStr;
    delete []tmpStr;

    return myString;
}


thanks,

Barry
 
Use wstring instead of string.
string isn't a unicode thingie.

/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
Ah, I see! However, now I have switched all my strings to wstrings and now I get a compiler error:
Code:
H:\Programs\MicrosoftVisualStudio.NET\Vc7\atlmfc\include\cstringt.h(37) : fatal error C1083: Cannot open include file: 'mbwstring.h'

I have searched all my directories and this header is nowhere to be found. I did install Unicode when I installed VS 7.0. I also looked on my work machine which has VS 6.0 sp5 which also had Unicode strings installed and this header file is not there either. Where am I supposed to get it from?


many thanks,

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top