Click here to Skip to main content
13,199,026 members (43,770 online)
Click here to Skip to main content
Add your own
alternative version

Stats

4.5K views
1 bookmarked
Posted 1 Dec 2011

C++: Converting an MFC CString to a std::string

, 1 Dec 2011
Rate this:
Please Sign up or sign in to vote.
LPSTR WideChar2MBCS( const CString& strCS ){ const UINT wLen = strCS.GetLength() + 1; UINT aLen = WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL); LPSTR lpa = new char[aLen]; WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL); return...
LPSTR WideChar2MBCS( const CString& strCS )
{
    const UINT wLen = strCS.GetLength() + 1;
    UINT aLen = WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL);
    LPSTR lpa = new char[aLen];
    WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);
    return lpa;
}
 
std::string WideChar2StdStr(const CString& strcs)
{
    LPSTR lpa = WideChar2MBCS(strcs);
    std::string stdStr(lpa);
    delete [] lpa;
    return stdStr;
}

I hope this will be useful.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

stonexin
Web Developer
China China
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 1 Dec 2011
Article Copyright 2011 by stonexin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid