#include <iostream>
#include <string>
#include<list>
using namespace std;
class Person
{
public:
int age;
int height;
string name;
Person(string name, int age, int height)
{
this->name = name;
this->age = age;
this->height = height;
}
};
void printList(const list<Person> &lst)
{
for ( list<Person>::const_iterator it = lst.begin(); it != lst.end(); it++)
{
cout << (*it).name << " " << (*it).age << " " << (*it).height << endl;
}
}
void test04()
{
list<Person> lst;
Person p1(string("刘备"), 35, 175);
Person p2("曹操", 45, 180);
Person p3("孙权", 40, 170);
Person p4("赵云", 25, 190);
Person p5("张飞", 35, 160);
Person p6("关羽", 35, 200);
lst.push_back(p1);
lst.push_back(p2);
lst.push_back(p3);
lst.push_back(p4);
lst.push_back(p5);
lst.push_back(p6);
printList(lst);
}
int main(void)
{
test04();
system("pause");
return 0;
}
这个代码运行到system("pause");时会停下来报错,报错如图
我调试了一下,发现把构造函数形参列表的顺序和创建成员变量的顺序统一,就可以解决问题了
求问,这是为什么
pause不知道要不要Windows.h
一切正常诶
system(“pause”)
VC 不知道可不可以用啊;DEVC++可以用
你试试看把system("pause");去掉行不行
可能加一下system("pause")头文件#include<stdlib.h>
🤔