Hi there! I have to read data from a file and load it into an array:
here is the data of the text file:
Team Creative
6
100 Anwar Khan
201 Belal Ahmed
150 Sara Amjad
400 Nida Khawar
342 Rehan Sheikh
341 Nadia Kanwal
My code is:
class Player
{
private:
char* name;
int id;
public:
Player();
};
class Team
{
private:
Player* players;
int No_Of_Players;
char* Name;
};
Team::Team(std::string FileName)
{
ifstream inFile;
string sTeam_Name;
inFile.open("input.txt");
if(!inFile)
{
cout << " error in opening file " << endl;
}
else
{
string sLine;
inFile >> Name; // reads the name of the team
inFile >> No_Of_Players; // reads the number of members
Team* t = new Team[No_Of_Players];
for (int i=0; i<No_Of_Players; i++)
{
getline(inFile,sLine,' ');
int id = atoi(sLine.c_str());
t[i].players->Set_Id(id);
}
}
}
I want to ask couple of things. I have done the work for the id's but the job for names is still left. What will be the 'syntax' for that?