I have a file whose content looks like this :
Aadam
50
Aadam
0
Aad
0123
Waleed
12345
Now, I need to store first line in a string array and second line into an integer array. This is the source code that I have written....
ifstream infile ("File.txt");
string name [20];
int score [20};
for (int i = 0; !infile.eof(); i++)
{
getline(infile, name[i]);
infile >> scores[i];
}
Well, the program reads first line successfully but after that it does nothing. I tried another method first, in which I store the integer first as a temporary string and then I convert that string into an integer using "stoi", which worked like a charm. Like this :
for (int i = 0; !infile.eof(); i++)
{
getline(infile, name[i]);
string temp;
getline(infile, temp);
scores[i] = stoi(temp);
}
But the problem is that I can't use stoi. It works fine in my computer but I have to provide the source code to my teacher who may not have the compiler which supports C++11. Which may be a problem for me. So I need another way to input data from the file. So, Kindly if you know a way to do this, please show me the way.