no match for operator in std cout

trying to print some data but keep getting an error. The error is located near the bottom in the printArray function.

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
#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;

#define MAX 30

struct cityInfo
{
char cityName[25];
int lowTemp;
int highTemp;
};

int buildarray(cityInfo[]);
void printArray(cityInfo[],int);
int numcity;


int main()
{
cityInfo cities[MAX];

numcity=buildarray(cities);
printArray(cities,numcity);



}



int buildarray(cityInfo cities[] )
{
cityInfo OneCity;

int numcity=0;

ifstream inFile;


inFile.open( "cities.txt", ios::binary );

if ( inFile.fail() )
   {
   cout << "The binary_cities.txt input file did not open";
   exit(-1);
   }
   
   cityInfo city;

inFile.read( (char *) &city, sizeof(cityInfo) );

while(inFile)
{
 cities[numcity]=OneCity;
 numcity++;
 
 inFile.read( (char *) &city, sizeof(cityInfo) );
 }
return numcity;

}




void printArray( cityInfo cities[], int numcity )
{


for( int sub = 0; sub < numcity; sub++ )
   cout<<cities[sub];
       
  }


What's the error?

Line 18, you are declaring a variable outside of main.

Ya, I see what might be the error. In order to print something out of a structure you have to use the member operator like with classes for each piece of data in the structure. so that would need to be... hmm. Not sure how you would write that with an array of structures. It would either be cities[sub].cityName or cities.cityName[sub]. I think it's the first since that makes more sense.
Last edited on
Topic archived. No new replies allowed.