C++string与VC++CString互转

//CString to string
string CStringToString(const CString &cstr)
{
    string str=cstr.GetBuffer(0);
    cstr.ReleaseBuffer();
    return str;
}

void CStringToStringEx(const CString &cstr, string &str)
{
    str=cstr.GetBuffer(0);
    cstr.ReleaseBuffer();
}

//string to CString
CString StringToCString(const string &str)
{
    CString cstr=str.c_str();
    return cstr;
}

void StringToCStringEx(const string &str, CString &cstr)
{
    cstr=str.c_str();
}

//CStringA to string
string CStringAToString(const CStringA &cstra)
{
    string str=cstra.GetBuffer(0);
    cstra.ReleaseBuffer();
    return str;
}

void CStringAToStringEx(const CStringA &cstra, string &str)
{
    str=cstra.GetBuffer(0);
    cstra.ReleaseBuffer();
}

//CStringW to string
string CStringWToString(const CStringW &cstrw)
{
    CStringA ctsra(cstrw.GetBuffer(0));
    cstrw.ReleaseBuffer();
    string str=cstra.GetBuffer(0);
    cstra.ReleaseBuffer();
    return str;
}

void CStringWToStringEx(const CStringW &cstrw, string &str)
{
    CStringA ctsra(cstrw.GetBuffer(0));
    cstrw.ReleaseBuffer();
    str=cstra.GetBuffer(0);
    cstra.ReleaseBuffer();
}

你可能感兴趣的:(C++string与VC++CString互转)