Error:no match for 'operator>>'

In my OpenFile function it should prompt user to enter a file name and read the file into an array. I keep getting the error: no match for 'operator>>' (operand types are std::ifstream {aka std::basic_ifstream<char>} and 'entryType'). I think the problem could be using a void function or declaring the array as part of entryType. I know that I'm getting this error because the compiler looked for a function that could handle (istream) >> (entryType) but found none. How would I fix my code to get rid of this error?

Header File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
include<string>
using namespace std;

enum Title {Mr, Mrs, Ms, Dr, NA};

struct NameType {
  Title title;
  string firstName;
  string lastName;
};

  struct AddressType {
  string street;
  string city;
  string state;
  string zip;
 };

struct PhoneType {
  int areaCode;
  int prefix;
  int number;
};

struct entryType {
  NameType name;
  AddressType address;
  PhoneType phone;
};

const int MAX_RECORDS = 50;

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
entryType bookArray[MAX_RECORDS]; // entryType declared in header file

int main()
{
   entryType userRecord;
   string filename;
   ifstream inData;
   char searchOption;

   OpenFile(filename, inData);

   MainMenu(inData, filename);

   return 0;
}

void OpenFile(string& filename, ifstream& inData)
{
   do {
       cout << "Enter file name to open: ";
       cin >> filename;

       inData.open(filename.c_str());

       if (!inData)
           cout << "File not found!" << endl;

   } while (!inData);


   if(inData.is_open())
   {

       for(int i=0; i<MAX_RECORDS;i++)
       {
           inData >> bookArray[i];

       }
   }
}
you just need to break it down more.
you need

indata >> bookArray[i].name;

for example.

or you can overload the >> operator to do something different.
You need to overload the >> operator for your entryType, st. like:
1
2
3
4
5
6
istream& operator>>(istream& is, entryType& et)
{
  //do the reading here

  return is;
}
Topic archived. No new replies allowed.