Comparing strings in C++

Discussion in 'OT Technology' started by Seadee456, Oct 25, 2005.

  1. Seadee456

    Seadee456 New Member

    Joined:
    Jul 29, 2002
    Messages:
    1,949
    Likes Received:
    0
    Location:
    Dallas, TX
    Does anybody know how to compare two strings and tell which one comes after the other alphabitically?
     
  2. kronik85

    kronik85 New Member

    Joined:
    Feb 8, 2005
    Messages:
    34,837
    Likes Received:
    0
    Location:
    Deutschland
    compare the first index..
     
  3. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    If the strings are std::strings you can use <, >, ==, etc.
    If the strings are char buffers, use strcmp() or convert to std::string.
     
  4. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yup. strncmp() FTW though.
     
  5. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    std::system("/usr/bin/perl");

    Sorry. I don't even know C++. I just remember fucking with string in C, and it sucks.
     
  6. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    :mamoru: Yeah, if you're writing a program that's mostly for string handling, C/C++ is not the right language to write it in. Perl/Python/Tcl are much better choices.
     
  7. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    perl string handling > *

    it has saved my ass MANY times. and the best part is, it's not hard to learn either.
     

Share This Page