comparing strings

This is a discussion on comparing strings within the C++ Programming forums, part of the General Programming Boards category; I want to compare a user defined string array with a string constant using the '==' operator. Is this possible. ...

  1. #1
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256

    comparing strings

    I want to compare a user defined string array with a string constant using the '==' operator. Is this possible. for example

    if(somestringarray == "Hello") then print "Good Morning"

    is there another way to do this? thanks



  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You can overload the == operator for your own string class, if you are so inclined.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Or make somestringarray a string variable. Eg:

    Code:
    #include <string>
    using namespace std;
    [..]
    char stringarray[] = "Hello";
    string somestringarray = stringarray;
    
    if (somestringarray == "Hello")
      cout << "Good morning" << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  2. Problem with comparing strings!
    By adrian2009 in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 09:44 PM
  3. comparing strings using argv
    By eth0 in forum C Programming
    Replies: 2
    Last Post: 09-20-2005, 09:20 AM
  4. comparing strings
    By infinitum in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2003, 12:10 PM
  5. Comparing Strings
    By Perica in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2003, 10:41 PM

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