Question: I am recieving build errors related to a C++ program involving structures. The build errors are as follows Error (active) no operator >> matches

I am recieving build errors related to a C++ program involving structures. The build errors are as follows "Error (active) no operator ">>" matches these operands" & "Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)" Both types of errors occur for both "<<" & ">>" operators.

The code is pasted below. Any help is appreciated. I am using Visual Studio 2015. I am happy to provide any additional information needed via the comments.

#include

#include

#include

using namespace std;

void readData(ifstream &fs, int &num, string names[], double diff[20], double Scores[][9])

{

fs >> num;

for (int i = 0; i < num; i++)

{

fs >> names[i];

fs >> diff[i];

for (int j = 0; j < 9; j++)

fs >> Scores[i][j];

}

}

void selectionSort(double A[9])

{

for (int i = 0; i < 8; i++) //For each element.

{

int min = i; //Assumes the first element in the remaining array as min.

for (int j = i; j < 9; j++) //Find the position of least element in remaining array.

if (A[j] < A[min])

min = j;

double temp = A[i]; //Exchange the first element in the array, with minimum element.

A[i] = A[min];

A[min] = temp;

}

}

void sortData(double A[][9], double totalScores[], double difficulty[], int num)

{

for (int i = 0; i < num; i++)

{

selectionSort(A[i]);

totalScores[i] = 0;

for (int j = 1; j < 8; j++)

totalScores[i] += A[i][j];

totalScores[i] *= difficulty[i];

}

}

void printData(string names[], double diff[], double Scores[][9], double total[], int num)

{

cout << "\tNAME\tDIFF\tSORTED SCORES\t\t\t\t\t\tPOINTS" << endl;

for (int i = 0; i < num; i++)

{

cout << setw(10) << names[i];

cout << setw(7) << fixed << setprecision(1) << diff[i];

for (int j = 0; j < 9; j++)

cout << setw(7) << fixed << setprecision(1) << Scores[i][j];

cout << setw(7) << fixed << setprecision(1) << total[i] << endl;

}

}

int findWinner(double tot[], int num)

{

int max = 0;

for (int i = 1; i < num; i++)

if (tot[i] > tot[max])

max = i;

return max;

}

int main()

{

double Scores[20][9];

string names[20];

double totalScores[20];

double difficulty[20];

ifstream fileStream;

fileStream.open("C://MP7.txt");

int num;

readData(fileStream, num, names, difficulty, Scores);

sortData(Scores, totalScores, difficulty, num);

printData(names, difficulty, Scores, totalScores, num);

int winnerIndex = findWinner(totalScores, num);

cout << "The winner of the tournament is: " << names[winnerIndex] << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!