i need help with array

for some reason the code keeps saying that there is no operator found that takes a right hand operand of type 'star_system', this is only up to the part where i need help

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
 #include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
//This is the structure that is used for this lab.
struct star_system {
	int num_detected_planets;
	int num_stars;
	string system_name;
	string spectral_type;
	double distance_from_sun;
};
//This function fills an array of structures with the appropriate data.
void fill_array(star_system arr[]) {
	arr[0].system_name = "Sun";
	arr[0].num_stars = 1;
	arr[0].num_detected_planets = 8;
	arr[0].spectral_type = "G";
	arr[0].distance_from_sun = 0.0;
	arr[1].system_name = "Wolf 359";
	arr[1].num_stars = 1;
	arr[1].num_detected_planets = 0;
	arr[1].spectral_type = "M";
	arr[1].distance_from_sun = 7.78;
	arr[2].system_name = "Alpha Centauri";
	arr[2].num_stars = 3;
	arr[2].num_detected_planets = 1;
	arr[2].spectral_type = "M,G,K";
	arr[2].distance_from_sun = 4.3;
	arr[3].system_name = "Tau Ceti";
	arr[3].num_stars = 1;
	arr[3].num_detected_planets = 5;
	arr[3].spectral_type = "G";
	arr[3].distance_from_sun = 11.89;
	arr[4].system_name = "Epsilon Indie";
	arr[4].num_stars = 3;
	arr[4].num_detected_planets = 0;
	arr[4].spectral_type = "K,T,T";
	arr[4].distance_from_sun = 11.82;
}
//This function provides a brief list of star system names,
//in the order they appear in the array.
void display_system_names(star_system arr[], int num_systems) {
	for (int n = 0; n < num_systems; ++n)
		cout << " "
		cout >> arr[n];
	cout << '\n';
}
cout >> arr[n];
should be << and also this insertion operator needs to be overload for struct star_system
You can display individual member variables without overloading but if you want to display all of them together you must overload. To print individually just write:

1
2
cout << "Number of Planets: " << arr[n].num_detected_planets << endl;
cout << "Number of Stars: " << arr[n].num_stars << endl;

//This must be done for every member variable.
Topic archived. No new replies allowed.