#include <vector>
#include <iostream>
#include <iomanip>
using namespace std;
typedef vector<double>row;
typedef vector<row>Matrix;
Matrix grade;
void read_matrix(Matrix&grade,vector<string>&names);

void display_matrix(const Matrix&grades,const vector<string>&names);

void read_matrix(Matrix&grade,vector<string>&names)
{ int grades;
  cout << "Reading data into a Matrix " << endl;
  cin >>grades;

if(grades== 0)
    {
      cout << "Making vector empty." << endl;
     grade.resize(0);
    }
else {
    grade.resize(grades);
    for (int i=0;i<grades;i++)
    {grade.at(i).resize(5);}
}
  int _student;
  cout << "Enter student name"<<endl;
  cin>>_student;
  names.resize(_student);
  for (int i= 0; i<names.size(); i++)
	{cin >> names.at(i);}
}

void display_matrix(const Matrix&grade,const vector<string>&names){
    cout<<"  ";
  for ( int j=0;j<names.size();j++)
   {cout<< setw(5)<<setprecision(2)<<names.at(j)<<" ";
   }
   for (int k=0;k<grade.size();k++)
   { cout<< setw(5)<<setprecision(2)<<grade.at(k)<<" "<<
   cout<<endl;}

}

Here I need to write a two dimensional arrays one to read in the grades,and another to read in the names of students,and then print them like : john 9.5
Sammy 10
and so on,but my compiler gives me an error like no match for "<< operator" is there something wrong with my code?

Recommended Answers

All 8 Replies

This seams you didn't include the header file "string".

void display_matrix(const Matrix&grade,const vector<string>&names){
cout<<" ";
for ( int j=0;j<names.size();j++)
{cout<< setw(5)<<setprecision(2)<<names.at(j)<<" ";
}
for (int k=0;k<grade.size();k++)
{ cout<< setw(5)<<setprecision(2)<<grade.at(k)<<" "<<
cout<<endl;}

}

Right there.

It still does not work,maybe my function definition for two dimensional vector is not right?

It still does not work,maybe my function definition for two dimensional vector is not right?

Maybe you sould post the exact error message and tell us the exact line the error points to. That way we don't have to guess.

double highest_mark(const Matrix&grades);//Function that computes the highest mark in the class.
double average(const Matrix&grades);//Function that computes the average.

//Function implementation

void read_matrix(Matrix& grades,vector<string>& names)
{ string students;
  cout << "Please enter student name"<<endl;
  cin>>students;
  if (students==0)
  { names.resize(0);}
  else{ names.resize(students);for(int i=0;i<names.size();i++)
  { cin>>names.at(i);}}
  double marks;
  cout <<"Enter marks for each student"<<endl;
  if (marks==0)
  { grades.resize(0);}
  else ( grades.resize(marks));{
     for (int i=0;i<grades.size();i++)
     { for (j=0;j<grades[i].size();j++)
     { grades[i][j]=i*j;}}

}}

     void display_matrix(const Matrix&grades,vector <string>&names)
     {

for (int i=0;i<names.size();i++)
      { cout<<names.at(i)<<" ";
        cout <<endl; }

        for( int i = 0 ; i < grades.size() ; i++ ){


      {cout << grades.at(i).at(j) << endl;}}
}


double highest_mark(const Matrix&grades)
{
  int largest=grades[0][0];
  for (int i=0;i<grades.size();i++)
  { if (grades[i][j]>largest)  largest=grades[i][j];
  }
  return largest;
}


double average(const Matrix&grades)
{ double av_mark;
    for (int i=0;i<grades.size();i++)
{ av_mark=grades[i][j]/i;}}

okay,here is my source code,I've remade it.the errors are:line 26)no match for operator == in students ==0.
line 28)no matching for function call to std::vector<std::basic string....
lines 36,51,59,68)j not declared in this scope.

I dont know what to do(

okay,here is my source code,I've remade it.the errors are:line 26)no match for operator == in students ==0.
line 28)no matching for function call to std::vector<std::basic string....
lines 36,51,59,68)j not declared in this scope.

I dont know what to do(

I don't see any students==0 anywhere around line 28. And there is no line 59, 68.

When I said "tell us the exact line the error points to" you have to tell us using the line numbers in the post.

ohhh,yeah I have written the lines from compiler,sorry)) so first error is on line 10,the second error is on line 12,and other lines are 20,35,43,52.And I've stated the errors in the previous posts.

How is students defined? Isn't it a string? And what string can possibly have the value 0? It might be "0", but never 0.

Does names.resize() take a string (students) as a parameter?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.