我写了一个程序,它应该只打印向量中的所有字符串。我正在使用迭代器。我得到的错误是:
no match for 'operator[]' in '((Students*)this)->Students::courses_[it]'
这是我的代码:
#include <vector>
#include <string>
#include <iostream>
using namespace std;
#include "../include/Courses.h"
class Courses;
class Students {
private:
string name_;
int id_;
public:
vector<string> courses_;
void print_courses(){
vector<string>::iterator it;
for(it=courses_.begin();it < courses_.end(); it++)
cout << this->courses_[it] << " ";
}