【发布时间】:2018-10-06 03:19:47
【问题描述】:
我目前是使用 C++ 的初学者,在试图弄清楚如何打印数据结构数组时遇到了一些麻烦。我一直在四处寻找解决方案,但是没有成功。以下是我的代码:
#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");
}
我想要做的是打印“人口”数组,我得到的错误是“没有运算符“
非常感谢任何帮助或解决方案,谢谢!
【问题讨论】: