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
    23,803
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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-12-2009, 11:56 PM
  2. string comparision
    By ulises_FITX in forum C Programming
    Replies: 9
    Last Post: 04-20-2007, 01:13 PM
  3. String comparision
    By FDHannibal in forum C++ Programming
    Replies: 8
    Last Post: 03-23-2006, 08:04 AM
  4. string comparision : Urgent problem
    By karanmitra in forum C Programming
    Replies: 17
    Last Post: 08-08-2005, 05:38 PM
  5. string comparision, sorting
    By guda in forum C++ Programming
    Replies: 5
    Last Post: 10-12-2004, 08:22 AM

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