compare vectors for inequality

Discussion in 'C' started by heidik, Jan 12, 2011.

  1. heidik

    heidik New Member

    Joined:
    Oct 23, 2010
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone

    I have to compare two vectors (having struct data from two different files) for inequality. The two vectors contain struct type of elements. E-g

    Code:
    Struct StructVect1
    {
    	string word_1;
    	string word_2;
    	string word_3;
    	string word_4;
    };
    
    Struct StructVect2
    {
    	string word_1;
    	string word_2;
    	string word_3;
    	string word_4;
    };
    
    and suppose vector1 has 10 (struct type) elements in it and vector2 has 5 (struct type) elements in it.

    I want to find out all those elements of vector1 the word_1 (e-g vect1.word_1) of which is NOT equal to word_4 of any element of the vector2 (e-g vect2[1].word_4, vect2[2].word_4, vect2[3].word_4, vect2[4].word_4).

    For example
    Code:
    if(
    vect1[0].word_1 != vect2[0].word_4
    vect1[0].word_1 != vect2[1].word_4
    vect1[0].word_1 != vect2[2].word_4
    vect1[0].word_1 != vect2[3].word_4
    )
    {
    	// push_back vect1[0] to vect3[0]
    }
    
    Could you please help.
     
    Last edited: Jan 12, 2011

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice