I'm trying to use an object name from the array. I know I wrote wrong code below inside the loop. How should I write code on the below pointer lines for using object name from the array?
Here's the full code:
#include <iostream>
using namespace std;
class Students{
public:
int index;
string name;
string father;
};
int main() {
string nname[] = {"John", "Doe"};
string fname[] = {"Ex John Father", "Ex Doe Father"};
int NarrSize = sizeof(nname)/sizeof(nname[0]); // Size of nname array
int FarrSize = sizeof(fname)/sizeof(fname[0]); // Size of fname array
if( NarrSize == FarrSize ){ // Check if both array size is same
for(int i=0; i<NarrSize; i++){
Students nname[i];
nname[i].index = i+1;
nname[i].name = nname[i];
nname[i].father = fname[i];
}
}
return 0;
}

Students nname[i];is not legal in c++ among other things. Like an off by 1 error and it goes out of scope at the next iterationstd::map<std::string,Students>