Thread: need HELP!!!!!!!!!C++ COMPARISONS

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    Question need HELP!!!!!!!!!C++ COMPARISONS

    The following code segment (it may have some errors in it) is comparing two strings to see if they are identical. I want to compare to see if they are the same names, not just the same length. Is this correct. if the 1st last nme is kennedy and the second last name is Eubanks(both names are 7 chars long) then will it pick up that these names are not the same? If not how can that be done without using C?


    lstname1= token.1substring(0,length)
    lstname2= token2.substring(o,length)

    bool compare (string a, string b)
    {
    if (lstname1==lstname2)
    return true;
    else
    return false;
    }

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    You can't use equivalence ops (==) to compare strings - use "strcmp"

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    RE:HELLLLLLLLP!!!!!!!!!

    I thought you could use relational ops on strings- it would just produce a cse insensitive comparison. I nvr learned C. I was told i can convert C++ strings to C, but then what?? or can I just use force every character in the string to lowercase before i can compare?

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    There's not a difference I'm aware of between C and C++ strings, but I could be wrong, so there'd be no need to "convert them from C++ to C"

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    A C style string is an array of characters.

    A C++ style string is an object of type std::string, as defined by <string>

    You should be able to use the == operator in the latter case but not the former.
    All generalizations are false

  6. #6
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    well shut my mouth and call me a monkey....

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    monkey
    All generalizations are false

  8. #8

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help!!c problem in math
    By feelsunny in forum Tech Board
    Replies: 2
    Last Post: 10-06-2007, 03:35 AM
  2. compare double value to 0 - unreliable comparisons warning
    By collymitch in forum C Programming
    Replies: 3
    Last Post: 04-04-2005, 07:38 PM
  3. no. of comparisons in linear/binary search
    By alice in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 06-05-2004, 10:55 PM
  4. Array Comparisons
    By B.C.Lioness in forum C++ Programming
    Replies: 8
    Last Post: 03-20-2004, 07:37 PM
  5. Replies: 2
    Last Post: 12-03-2001, 02:32 AM