Howdy, Stranger!

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

Categories

cstring to string

mr_emptymr_empty Member Posts: 1
hi all,

how to convert cstring to string? thanks!

Comments

  • paulshaynespaulshaynes Member Posts: 3
    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

  • LundinLundin Member Posts: 3,711
    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.
  • paulshaynespaulshaynes Member Posts: 3
    : 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.

  • TribalTechTribalTech Member Posts: 74
    : 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.