我是C ++场景的新手,我想将我的Vector内容打印到屏幕上。我无法找到能够打印出向量中的内容的正确代码,因为我不断收到错误:“错误:无效的操作数到二进制表达式('ostream'(又名'basic_ostream')和'value_type'(又名'S_type'))|“
我将提供我拥有的所有代码。我尝试了不同的东西试图打印矢量,如“cout<
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
enum G_type {Dandy, Okay, Weak, Undefined}; // enumerated type for grades
struct S_type // defines a student record
{
int ID;
int Score;
G_type Grade;
};
vector<S_type> Roll; // vector to store student records
// declare all function prototypes
void Init_Roll ( vector<S_type>& R);
int Avg_Score (vector<S_type> R);
void Assign_Grades (vector<S_type>& R, int Avg);
void Print_Roll (vector<S_type> R);
int main()
{
for(int i=0; i<Roll.size();i++)
cout << Roll[i];
return 0;
} // end of main
// define all your functions below
void Init_Roll (vector<S_type>& R){
S_type s; //to assemble temporary record
//use the test data provided to insert 12 student records, one by one;
s.ID=108;s.Score=85;s.Grade=Undefined;
R.push_back(s);
s.ID=122;s.Score=73;s.Grade=Undefined;
R.push_back(s);
s.ID=130;s.Score=62;s.Grade=Undefined;
R.push_back(s);
s.ID=140;s.Score=70;s.Grade=Undefined;
R.push_back(s);
s.ID=147;s.Score=80;s.Grade=Undefined;
R.push_back(s);
s.ID=240;s.Score=92;s.Grade=Undefined;
R.push_back(s);
s.ID=320;s.Score=88;s.Grade=Undefined;
R.push_back(s);
s.ID=325;s.Score=58;s.Grade=Undefined;
R.push_back(s);
s.ID=350;s.Score=67;s.Grade=Undefined;
R.push_back(s);
s.ID=400;s.Score=79;s.Grade=Undefined;
R.push_back(s);
s.ID=420;s.Score=85;s.Grade=Undefined;
R.push_back(s);
s.ID=500;s.Score=72;s.Grade=Undefined;
R.push_back(s);
}//end of Init_Roll
int Avg_Score (vector<S_type> R){
int sum = 0;
for(int k=0;k<R.size();k++)
sum = sum + R[k].Score;
return sum/R.size();
}//End of Avg_Score
void Assign_Grades (vector<S_type>& R, int Avg){
for(int k=0;k<R.size();k++){
if(R[k].Score<Avg-10)
R[k].Grade = Weak;
else if(R[k].Score>Avg+10)
R[k].Grade = Dandy;
else
R[k].Grade = Okay;
}
}//End of Assign_Grades
void Print_Roll (vector<S_type> R){
for(int k=0;k<R.size();k++){
switch(R[k].Grade){
case Dandy: cout<<"Dandy";
break;
case Okay: cout<<"Okay";
break;
case Weak: cout<<"Weak";
break;
case Undefined: cout<<"Undefined";
break;
}
}
for(int i=0;i<R.size();i++){
cout<<"ID: " << R[i].ID << " Score: " << R[i].Score << cout << " Grade: " << R[i].Grade << '\n';
}
}//End of Print_Roll
问题是,如何将Roll矢量打印到屏幕上?