how to display [k]
Jun 18, 2019 at 5:01am UTC
i want to display [k], however its keep getting error at the "cout << setw(3) <<nParents[k] << ' ';" and said that subscript requires array or pointer type
i assign [k] as int
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
void parent_selection()
{
//read result file
ifstream inpResult ("Result12rou.txt" ); //read result
//assign result into array
for (i = 0; i < pop_size; i++ )
{
for ( j = 0; j < no_of_facloc; j++ )
{
inpResult >> Result[i][j];
//cout << "Result["<<i<<"]["<<j<<"]="<< Result[i][j]
<<endl;
}
}
// random parent selection
parents = pop_size * parent_rate;
for (k = 0; k < parents; k++)
{
nParents = rand()% pop_size;
//nParents[k] = nparents [k][j];
cout << setw(3) <<nParents[k] << ' ' ;
}
cout<< endl;
}
Last edited on Jun 18, 2019 at 5:02am UTC
Jun 18, 2019 at 5:13am UTC
> and said that subscript requires array or pointer type
It's complaining about nParents not being an array or a pointer.
Last edited on Jun 18, 2019 at 5:14am UTC
Jun 18, 2019 at 6:42am UTC
thank you.. i got the solution for this problem
Topic archived. No new replies allowed.