-4
因此,這裏是我的程序出現錯誤:用迭代器解決c2100問題?
// ConsoleApplication42.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <list>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
const int numberOfStudents = 9;
string names[numberOfStudents] = {"Abe","Billy","Carl","Dillan","Eddie","Felix","Gill","Herald","Isaac"};
struct StudentInfo {
string name;
int grade;
bool operator< (int grade){
return grade < grade;
}
bool operator< (string name){
return name < name;
}
};
void populateStudentRecords(vector<StudentInfo>Students,vector<int>::iterator iter, int x){
for(auto iter = Students.begin(); iter != Students.end(); ++iter){
iter->name = names[x];
iter->name.push_back(x);
iter->grade = x++;
x = x++;
}
}
bool sortByName(const StudentInfo x, const StudentInfo y){
return x.name < y.name;
}
bool sortByGrade(const StudentInfo x, const StudentInfo y){
return x.grade < y.grade;
}
void displayRecords(vector<StudentInfo>Records,vector<int>::iterator iter){
for(auto iter = Records.begin(); iter != Records.end(); ++iter){
cout<<*iter->name<<" -"<<*iter->grade<<endl;
}
}
void displayMaxAndMinGrade(vector<StudentInfo>Records,vector<int>::iterator iter){
for(auto iter = Records.begin(); iter != Records.end(); ++iter){
cout<<*iter->name<<" - " <<*iter->grade<<endl;
iter = Records.end();
cout<<*iter->name<<" - " <<*iter->grade<<endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<StudentInfo>Records (numberOfStudents);
vector<int>::iterator iter;
populateStudentRecords(Records,iter,0);
sort(Records.begin(),Records.end(),sortByName);
displayRecords(Records,iter);
sort(Records.begin(),Records.end(),sortByGrade);
cout<<" "<<endl;
displayMaxAndMinGrade(Records, iter);
return 0;
}
在displayRecords功能和displayMaxAndMin功能,我旁邊的迭代器的*符號。我希望計算機在向量中每次出現結構時顯示這些變量的值。但是,當我嘗試構建程序時,出現錯誤c2100。我試圖運行該程序時不包含*符號,但顯示每個變量的地址並導致崩潰。我該如何解決?謝謝。
據到https:/ /msdn.microsoft.com/en-us/library/bzf3eha6.aspx,c2100表示「間接運算符(*)應用於非指針值。」非常好的暗示,你不想*。 – user4581301