compare CString

Discussion in 'C++' started by Carl Forsman, Nov 17, 2008.

  1. Carl Forsman

    Carl Forsman Guest

    how to compare a CString?

    the following does not seem to work.

    CString id = PictureEntries.attribute("id").value();

    if (id.Compare("2222") == 1){
    cout << id << endl;
    }
     
    Carl Forsman, Nov 17, 2008
    #1
    1. Advertising

  2. Carl Forsman

    Ian Collins Guest

    Carl Forsman wrote:
    > how to compare a CString?
    >

    Try a windows group, CString isn't standard C++.

    --
    Ian Collins
     
    Ian Collins, Nov 17, 2008
    #2
    1. Advertising

  3. Carl Forsman

    Salt_Peter Guest

    On Nov 16, 10:14 pm, Carl Forsman <> wrote:
    > how to compare a CString?
    >
    > the following does not seem to work.
    >
    > CString id = PictureEntries.attribute("id").value();
    >
    > if (id.Compare("2222") == 1){
    > cout << id << endl;
    > }


    Whats a CString?

    As a hint: what is the difference between a null terminated sequence
    of characters and one that isn't null terminated? The point here is
    that if you don't know or aren't sure, use a little brain power:

    CString id("abcdef")
    if( id.Compare( CString("abcdef") )
    {
    // do stuff
    }
     
    Salt_Peter, Nov 17, 2008
    #3
  4. Carl Forsman

    David Connet Guest

    Salt_Peter <> wrote in news:f28eec71-822f-4894-9332-
    :

    > On Nov 16, 10:14 pm, Carl Forsman <> wrote:
    >> how to compare a CString?
    >>
    >> the following does not seem to work.
    >>
    >> CString id = PictureEntries.attribute("id").value();
    >>
    >> if (id.Compare("2222") == 1){
    >> cout << id << endl;
    >> }

    >
    > Whats a CString?
    >
    > As a hint: what is the difference between a null terminated sequence
    > of characters and one that isn't null terminated? The point here is
    > that if you don't know or aren't sure, use a little brain power:
    >
    > CString id("abcdef")
    > if( id.Compare( CString("abcdef") )
    > {
    > // do stuff
    > }


    Which is why you shouldn't ask CString questions here! The above is
    wrong.

    if (0 == id.Compare("abcdef"))
    {
    // do stuff
    }

    or

    if (id == "abcdef")
    {
    }

    The OP also asked in an MS group and "learned" how to make the proper
    call. Though the term RTFM was missing in those posts.

    Dave Connet
     
    David Connet, Nov 17, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    4,609
  2. yeye yaya

    I hate cstring!!!

    yeye yaya, Jul 11, 2003, in forum: C++
    Replies:
    7
    Views:
    2,749
    Stuart Golodetz
    Jul 11, 2003
  3. Rajesh Garg

    Why is CString not preferred

    Rajesh Garg, Jul 22, 2003, in forum: C++
    Replies:
    11
    Views:
    814
    Mike Wahler
    Jul 24, 2003
  4. Markus Hämmerli
    Replies:
    6
    Views:
    7,891
    Peter van Merkerk
    Sep 4, 2003
  5. John Smith

    Parsing char array to CString

    John Smith, Sep 6, 2003, in forum: C++
    Replies:
    4
    Views:
    7,263
    Pat McCormack
    Sep 9, 2003
Loading...

Share This Page