I'm currently a beginner with using C++ and I am having some trouble trying to figure out how to print an array of data structures. I have been searching around to try and find a solution for this however, I have been unsuccessful. Below is my code:
#include <iostream>
#include <string>
using namespace std;
int P = 5;
int N = 5;
//Create individual
typedef struct
{
int gene[5];
int fitness;
} individual;
//Population array contains all individuals
individual population[5];
//Initialize genes and fitness level of each individual in the the
population
int initializeGenes()
{
for (int i = 0; i < P; i++) {
for (int j = 0; j < N; j++) {
population[i].gene[j] = rand() % 2;
}
population[i].fitness = 0;
}
return 0;
}
int main()
{
initializeGenes();
for (int i = 0; i < P; i++)
{
cout << population[i];
}
system("pause");
}
What I am wanting to do is print the 'population' array and the error i'm getting says 'no operator "<<" matches these operands, operands types are std::ostream << individual" and I do not understand how to fix this.
Any help or a solution would be very much appreciated, thanks!