But if you need to continue with the existing file format, you might try something like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int count = 0;
string line;
while (getline(file, line, '}'))
{
istringstream ss(line);
ss.ignore(100, '{');
int a, b;
float c, d, e;
char ch;
if (ss >> a >> ch >> b >> ch >> c >> ch >> d >> ch >> e)
{
// store in fielddata[count] here
count++;
}
}
i've been trying to make this for loop work properly and display the field id with the highest yield per hectare, this is what i tried but it returns the wrong id. I've tried playing around with it but no luck
1 2 3 4 5 6 7 8
for (int i = 0; i < 8; i++)
{
if (fielddata[i].Yph > highyph)
highyph = fielddata[i].Field;
}
cout << "The Field with the Highest Yield is " << highyph << endl;