How to compare CString and CArray?

This is a discussion on How to compare CString and CArray? within the C++ Programming forums, part of the General Programming Boards category; I declare these below data Code: CString Hash[2] = {"208803DD4D","146DB1CB1C"}; CArray<unsigned char, unsigned char> hashdata; and hashdata have some value ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Lightbulb How to compare CString and CArray?

    I declare these below data
    Code:
    CString Hash[2] = {"208803DD4D","146DB1CB1C"};
    CArray<unsigned char, unsigned char> hashdata;
    and hashdata have some value
    I compare CArray and CString like these

    Code:
    if (hashdata == Hash[0])
    	{
    	......
                    .....
                    .....	
    }
    but there is error message show

    error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'const class CArray<unsigned char,unsigned char>' (or there is no acceptable conversion)

    Do I need to change CArray to other type of data? If you know how to solve my problem, please tell me.
    Thank you very much.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    have not used CArray but I have used CList and CMap and I know they are similar. You can't compare against the entire array you must compare against it's elements. You need to iterate thru the array and compare each element until you find the one you want. There is sample code on the msdn website for how to itrate thru the members.

    Code:
    CArray<CPerson*, CPerson*> myArray;
    
    int i=0;
    while (i < myArray.GetSize() )
    {
        if( myArray.GetAt( i++ ) == myvar )
           domycode();
    }
    Last edited by bonkey; 10-14-2002 at 12:56 PM.
    Best Regards,

    Bonkey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing CObjects with Serialization to CArchive
    By ruben_gerad in forum C++ Programming
    Replies: 0
    Last Post: 11-09-2006, 08:25 AM
  2. Copy Constructor with classmember CArray
    By zikje in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2006, 10:54 AM

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