0

So I'm trying to get the file to equate the struct type (in here Patient[i].BType == 'A'). Logic behind it is if that struct in the file reads A, output something. Its giving me errors of: error: no match for 'operator==' in 'Patient[i].Person::BType == 'A'' error: no match for 'operator==' in 'Donor[i1].Person::BType == 'A''

Any idea on how to match that type of struct array with a specific character it holds?

struct Person{
string surname;
string BType;
string organ;
int age;
int year, ID;
} Patient[50], Donor[50];

Then the code in interest is:

for (i = 0; i < 5; i++){
    for (i1 = 0; i1 < 5; i1++){
        if ((Patient[i].BType == 'A') && (Donor[i1].BType == 'A')){
            cout << Patient[i].surname << "  " << Donor[i1].surname;
        }
    }
}

3 Answers3

0

Simply change the single quotes to double quotes:

(Patient[i].BType == "A") && (Donor[i1].BType == "A")

Btype is of type std::string, and can be compared with string literals (double quotes), but not of objects of type char (single quotes).

You can find more information here which lists all the available operator==.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166
0

BType is a string. You should compare it with a string "A" not a char 'A'.

John Yang
  • 547
  • 1
  • 8
  • 21
0

You are comparing a std::string with a single char, change

if ((Patient[i].BType == 'A') && (Donor[i1].BType == 'A'))

to

if ((Patient[i].BType == "A") && (Donor[i1].BType == "A")) 

With the double quote, "A" is a C-style string, while single quote 'A'is a single char.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294