Howdy, Stranger!

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

Categories

How could i convert CString-->char?

IndrekSntIndrekSnt Member Posts: 69
:(

Comments

  • IndrekSntIndrekSnt Member Posts: 69
    : :(
    : I mean how could i get the (text) out of that CString?

  • stoberstober Member Posts: 9,765 ✭✭✭
    [b][red]This message was edited by stober at 2003-4-23 12:5:51[/red][/b][hr]
    : : :(
    : : I mean how could i get the (text) out of that CString?
    :
    :
    [code]
    CString str;
    char* s = str.GetBuffer(0);
    [/code]




  • IndrekSntIndrekSnt Member Posts: 69
    : [b][red]This message was edited by stober at 2003-4-23 12:5:51[/red][/b][hr]
    : : : :(
    : : : I mean how could i get the (text) out of that CString?
    : :
    : :
    : [code]
    : CString str;
    : char* s = str.GetBuffer(0);
    : [/code]
    :
    :
    :
    :
    : wow thanks a lot! :)


  • dwccgcdwccgc Member Posts: 576
    [blue]
    If you use the pointer returned by GetBuffer to change the string contents, you must call[/blue][red] ReleaseBuffer()[/red][blue] before using any other CString member functions.
    [/blue]



    : : [b][red]This message was edited by stober at 2003-4-23 12:5:51[/red][/b][hr]
    : : : : :(
    : : : : I mean how could i get the (text) out of that CString?
    : : :
    : : :
    : : [code]
    : : CString str;
    : : char* s = str.GetBuffer(0);
    : : [/code]
    : :
    : :
    : :
    : :
    : : wow thanks a lot! :)
    :
    :
    :

  • TheSunGodTheSunGod Member Posts: 8
    CStrin s;
    char cbuf[s.GetLength()+1];
    sprintf(cbuf,"%s",s);

  • dwccgcdwccgc Member Posts: 576
    : CStrin s;
    : char cbuf[s.GetLength()+1];
    : sprintf(cbuf,"%s",s);
    :
    :
    [code]
    CString s;
    char cbuf[s.GetLength()+1];
    sprintf(cbuf,"%s",s);
    [/code]
    [red] char cbuf[s.GetLength()+1];[/red][blue] returns three errors with MVC 6.0
    error C2057: expected constant expression
    error C2466: cannot allocate an array of constant size 0
    error C2133: 'cbuf' : unknown size
    [/blue]
  • stoberstober Member Posts: 9,765 ✭✭✭
    : : CStrin s;
    : : char cbuf[s.GetLength()+1];
    : : sprintf(cbuf,"%s",s);
    : :
    : :
    : [code]
    : CString s;
    : char cbuf[s.GetLength()+1];
    : sprintf(cbuf,"%s",s);
    : [/code]
    : [red] char cbuf[s.GetLength()+1];[/red][blue] returns three errors with MVC 6.0
    : error C2057: expected constant expression
    : error C2466: cannot allocate an array of constant size 0
    : error C2133: 'cbuf' : unknown size
    : [/blue]

    That's right -- you can't do that with any compiler.
    [code]
    CString s;
    char* buf = new char[s.GetLength()+1];
    strcpy(buf,(LPCTSTR)s);

    or
    char* buf = strdup((LPCTSTR)s);

    [/code]


    :

Sign In or Register to comment.