c_str() from CString

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Lidström

    #1

    c_str() from CString

    Hi,

    how can I get the c_str() from a CString? The only way I've found is this:
    const char* str = (LPCSTR)cstring ;

    --
    Daniel
  • Tom Shelton

    #2
    Re: c_str() from CString

    On Mon, 13 Sep 2004 12:16:08 +0200, Daniel Lidström wrote:
    [color=blue]
    > Hi,
    >
    > how can I get the c_str() from a CString? The only way I've found is this:
    > const char* str = (LPCSTR)cstring ;[/color]

    May I enquire what your purpose for this would be? It may influence the
    answers you receive if we new what you were actually trying to accomplish
    in a more fleshed out context :)
    --
    Tom Shelton [MVP]

    Comment

    • Daniel Lidström

      #3
      Re: c_str() from CString

      On Tue, 14 Sep 2004 00:24:53 -0600, Tom Shelton wrote:
      [color=blue]
      > On Mon, 13 Sep 2004 12:16:08 +0200, Daniel Lidström wrote:
      >[color=green]
      >> Hi,
      >>
      >> how can I get the c_str() from a CString? The only way I've found is this:
      >> const char* str = (LPCSTR)cstring ;[/color]
      >
      > May I enquire what your purpose for this would be? It may influence the
      > answers you receive if we new what you were actually trying to accomplish
      > in a more fleshed out context :)[/color]

      I want to put the contents of a CString into my own String class, or a
      std::string.

      --
      Daniel

      Comment

      • Mihai N.

        #4
        Re: c_str() from CString

        >>> const char* str = (LPCSTR)cstring ;
        [color=blue]
        > I want to put the contents of a CString into my own String class, or a
        > std::string.[/color]

        The cast to LPCSTR will do.

        But if the application is Unicode, you will run into problems.
        You should use LPCTSTR to be generic. Also, you should
        provide a way to use std::wstring for Unicode application and
        std::string for ANSI applications.

        Same notes for your own class.

        --
        Mihai
        -------------------------
        Replace _year_ with _ to get the real email

        Comment

        Working...