views:

327

answers:

4

I tried to make character by character comparison under string type, with the following code:

vector <int> getQuality(string seedTag, vector <string> &MuTag) { 

    vector <int> Quals;  

     for (unsigned i = 0; i<MuTag.size(); i++) { 
         Quals.push_back(-40);
         cout << MuTag[i] << " " << seedTag[i] << endl;

         if (MuTag[i] == seedTag[i]) { // This line 33 with error
           Quals.push_back(40);
         }


     }

     return Quals;
}

But why it gives such error:

 Mycode.cc:33: error: no match for 'operator==' in '(+ MuTag)->std::vector<_Tp, _Alloc>::operator[] [with _Tp = std::string, _Alloc = std::allocator<std::string>](((long unsigned int)i)) == seedTag. std::basic_string<_CharT, _Traits, _Alloc>::operator[] [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((long unsigned int)i)

How can I resolve it?

+5  A: 

You are trying to compare a string (MuTag[i]) with a char (seedTag[i]).

Alexander Prokofyev
+4  A: 

As Alexander said, you are comparing a string and a char.

The sad thing is that the compiler already told you that, only it encrypted it in ISO-STL-TEMPLATE encryption, which is more difficult to read that perl!

You may want to look at this script for decrypting C++ STL error messages.

Gilad Naor
an extra +1 for the humour
HRJ
+1  A: 
vector <string> & MuTag

is collection of strings , while

string seedTag

is collection of chars. So in you comparison

MuTag[i] == seedTag[i]

you actually comparing something like this

 "aaaaa" == 'a'

which is definitely not correct.

inazaruk
+2  A: 

I know plenty of other people have given a response to what is causing the compilation error, so let me recap and then propose a solution:

seedTag is a string, which by definition is an ordered collection of characters. MuTag is defined as a vector of strings: an ordered collection of strings.

When you do your comparison:

MuTag[i] == seedTag[i]

as other people have said, you're not comparing the same type.

To fix it:

By the looks of things, you're wanting to compare each of the values in MuTag with seedTag. If that is indeed the case, just get rid of the [i] in "seedTag[i]".

Smashery