按照黑马视频敲的vectorfor循环报内存错误,完全不知道怎么改
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
class Person
{
public:
Person(string name, int age)
{
m_Name = name;
m_Age = age;
}
public:
string m_Name;
int m_Age;
};
int main()
{
vector<Person> v;
//v.reserve(100);
Person p1("cpp", 12);
Person p2("tom", 13);
v.push_back(p1);
//cout << v.size() << endl;
v.push_back(p2);
//cout << v.size() << endl;
for(vector<Person>::const_iterator it = v.begin(); it != v.end(); it++)
{
cout << "姓名" << (*it).m_Name << "年龄" << (*it).m_Age << endl;
}
return 0;
}
有没有哪个大神告诉我问题出现在哪里,已经困扰了几天!!!