1. 首页
  2. 数据库
  3. 其它
  4. c++ emplace_back与push_back

c++ emplace_back与push_back

上传者: 2021-01-15 06:57:15上传 PDF文件 21.33KB 热度 14次
容器的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
下载地址
用户评论