cstring to string

hi all,

how to convert cstring to string? thanks!

Comments

  • Hi,

    Having to periodically do exactly what you want to do above, I decided to write a little class to do all this jiggery pokery for me: Try these two functions from my wrapper class CString2...

    std::string CString2::getstdstr(CString s)
    {
    return static_cast(CStringA(s));
    }

    CString CString2::getcstring(std::string str)
    {
    return CString(str.c_str());
    }

    I'm using .NET VC++ 2005, and the above works fine. However, However, I couldn't get some code snippets from the web which claimed to do the same to work.. so I guess this conversion is compiler specific.

    Anyway, hope this helps !

    Paul

  • Naturally it will be compiler-specific since "CString" is a MS invention and not part of the C++ standard. It is not supported by any other compiler than VC++, afaik.
  • : Naturally it will be compiler-specific since "CString" is a MS
    : invention and not part of the C++ standard. It is not supported by
    : any other compiler than VC++, afaik.

    But the other web versions used VC++ - i'm assuming they were on earlier versions.

  • : hi all,
    :
    : how to convert cstring to string? thanks!
    :

    CString's .GetBuffer() function gets you a char pointer to the null terminated string...if that's all you need access to.
    TT
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories