Learning structures

The structures are new to me. I'm just trying read from a file right now. This is my code I keep getting C2679 Error. Although I read about it I can't seem to resolve it. Also question about the array that is the type of my structure do I just treat that like a normal array? Thanks

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

const int SIZE = 10;

//structure
struct infoType
{	
	//blue brint
	string fname;
	string lname;
	string address;
	string phone;
};

// Function to get info from file.
void readData(ifstream &fin, infoType tele[], int& size)
{
	int plasticSize;
	while(!fin.eof())
	{
	fin >> tele[plasticSize].fname ;


	}


}



void displayMenu()
{
	cout << "Phone Directory Program " << endl;
	cout << endl;
	cout << "Options" << endl;
	cout << "[A]dd and entry to the phone directory. " << endl;
	cout << "[D]elete an entry from the phone directory. " << endl;
	cout << "[U]pdate an entry from the phone directory. " << endl;
	cout << "[L]ist the entire phone directory. " << endl;
	cout << "[E]xit the menu" << endl;
}










int main()
{
	ifstream fin("input.txt");
	//size
	int newSize = 0;
    infoType tele[SIZE];
	

	 readData(fin, tele, newSize );

	 for (int i = 0 ; i < newSize ; i++ )
	 {
		cout << tele[i] << endl;
			// ERROR here <<
	 
	 }

  
 
 displayMenu();
 
 system("pause");

 
 return 0;
}
Last edited on
When saying you get a certain error, please quote the entire error text. Error message numbers vary by compiler, and we have no idea what compiler you're using from your post.

At line 67, you're trying to output tele[i]. The compiler is telling you it doesn't know how to output an item of type infoType. If infoType were a class, you could overload the << operator to output an item of type infoType, but as long as infoType is a struct, you can't overload the << operator.

What exactly did you expect to happen when doing a cout of tele[i] ?

Best way to handle this is to write a function that takes an instance of infoType as an argument and outputs the individual members.

1
2
3
4
5
6
7
8
9
void Display_infoType (ostream & os, const infotype & it)
{ os << "Last name: " << it.lname << endl;
   os << "First name: " << it.fname << endl;
   os << "Address: " << it.address << endl;
   os << "Phone: " << it.phone << endl;
}

...
   Display_infoType (cout, tele[i]);

I thought it would output like an array. I don't know, thanks though.
Topic archived. No new replies allowed.