c++ emplace_back与push_back
容器的emplace_back与push_back方法 emplace_back针对添加的元素为 “某个对象struct、class” ,可以直接写参数,函数自动调用构造函数,而不用先创建对象再添加。 push_back需要先创建对象,再添加。 emplace、emplace_front类似 #include #include #include using namespace std; struct person { string name; string age; person(string _n, string _a) :name(_n),age(_a) {} }; int m
下载地址
用户评论