Thread: chars not equal

  1. #1
    Mmm. Purple.
    Join Date
    May 2002
    Posts
    154

    chars not equal

    Code:
    char a[6]="hello";
    char b[6]="hello";
    
    if(a <> b)
    {cout<<"not equal";}
    why does it always print not equal!

  2. #2
    Terrance11
    Guest
    use strings like this:

    #include <string>
    using namespace std;

    int main()
    {
    string h = "hello world";
    string i = "hello world";

    return 0;
    }

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: chars not equal

    Originally posted by krappykoder
    Code:
    char a[6]="hello";
    char b[6]="hello";
    
    if(a <> b)
    {cout<<"not equal";}
    why does it always print not equal!
    First, <> is not an operator in C++. != is the operator for "not equal to"

    Also, you can't compare char arrays like that directly, you'd have to use a function like strcmp in the string header, or you can use a string class.

    if you want to get it to work, then #include<string>

    then type

    using namespace std;

    then do

    char a[6]="hello";
    char b[6]="hello";

    if( strcmp( a, b ) )
    {cout<<"not equal";}

  4. #4
    >>string h = "hello world";
    >>string i = "hello world";

    When ever i do this and i include string.h it gives me string undifiend can anyone post me a copy of there string header file thnx

    -Devouring One-
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    that's because you have to do

    #include<string>

    using std::string;

    notice it's string not string.h

    Also, the typedef for string is in the std namespace

  6. #6

    Talking

    thanks it works now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. while condition question..
    By transgalactic2 in forum C Programming
    Replies: 3
    Last Post: 04-04-2009, 04:49 PM
  2. Why aren't 2 chars equal?
    By seraph in forum C++ Programming
    Replies: 5
    Last Post: 04-25-2007, 12:52 PM
  3. Wierd chars...
    By mikahell in forum C++ Programming
    Replies: 8
    Last Post: 08-06-2006, 07:18 PM
  4. fancy strcpy
    By heat511 in forum C++ Programming
    Replies: 34
    Last Post: 05-01-2002, 04:29 PM
  5. how can 0.00665 not equal 0.00665??!!
    By Susan in forum C++ Programming
    Replies: 10
    Last Post: 02-10-2002, 02:33 AM