Question about string comparision

This is a discussion on Question about string comparision within the C++ Programming forums, part of the General Programming Boards category; I am currently reading Jumping into C++ and the author states you can use comparision operators to compare two strings ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    13

    Question about string comparision

    I am currently reading Jumping into C++ and the author states you can use comparision operators to compare two strings and see which comes first in aplhabetical order. I am unsure how to do this. Which comparison would you do to compare a string alphabeticaly? how is this comparision being done at the program level? does it use the ascii values?

    Thank you for your time and expertise.

    Jonathan

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,256
    Quote Originally Posted by Mathieas
    the author states you can use comparision operators to compare two strings and see which comes first in aplhabetical order. I am unsure how to do this. Which comparison would you do to compare a string alphabeticaly?
    Note that by "strings" the author most likely means std::string objects. Given two such strings s1 and s2, you might write s1 < s2.

    Quote Originally Posted by Mathieas
    how is this comparision being done at the program level?
    operator< is overloaded to compare character by character.

    Quote Originally Posted by Mathieas
    does it use the ascii values?
    Assuming that ASCII is in use, yes.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    13
    That makes perfect sense, thank you for your time!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about comparision
    By curious in forum C Programming
    Replies: 9
    Last Post: 06-13-2009, 12:56 AM
  2. string comparision
    By ulises_FITX in forum C Programming
    Replies: 9
    Last Post: 04-20-2007, 02:13 PM
  3. String comparision
    By FDHannibal in forum C++ Programming
    Replies: 8
    Last Post: 03-23-2006, 09:04 AM
  4. string comparision : Urgent problem
    By karanmitra in forum C Programming
    Replies: 17
    Last Post: 08-08-2005, 06:38 PM
  5. string comparision, sorting
    By guda in forum C++ Programming
    Replies: 5
    Last Post: 10-12-2004, 09:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21