No match for operator erro in C++

Hi
While compiling my code it give me error. Please help me ....

[Error] no match for 'operator>' (operand types are 'std::string {aka std::basic_string<char>}' and 'int')


code .......


float gp1,gp2;

if(total==0)
{
cout<<"No Data is Entered .......";
} else
{
for(int i=0;i<total;i++)
{
if( arr4[i] > 3 || arr4[i]==3)
{
gp1++;
}
else if(arr4[i]<3.00 || arr4[i]==2.00)
{
gp2++;
}
}

cout<<"\n\nTHE number of student who got gpa greter than 3 is "<<gp1<<endl;
cout<<"\n\nTHE number of student who got gpa greter than 2 is "<<gp2<<endl;
}
Well, you can't compare an int and a string. 42 is not greater than "apple". Case closed.

The only time you use the > operator is on the line where you have "arr4[i] > 3", and you have failed to provide the definition for arr4. Of course, it must be a container of std::string, based on your error message.

So perhaps... change your arr4 to be an array of doubles instead of strings. And use doubles, not floats.

PS:
if( arr4[i] > 3 || arr4[i]==3)
There's an operator that combines > and ==, it's written as >= in C++.
Last edited on
Topic archived. No new replies allowed.