vector中的push_back
时间: 2024-05-18 17:14:11 浏览: 98
C++ 中push_back方法得使用
3星 · 编辑精心推荐
在C++的vector容器中,push_back函数用于在容器的末尾添加一个元素。它接受一个参数,表示要添加的元素的值。具体实现上,push_back函数会在容器中分配新的内存空间,并将新元素添加到末尾。如果当前的容量不足以容纳新元素,vector会自动分配更大的内存空间,并将原有的元素复制到新的空间中。因此,使用push_back函数可以方便地将新元素添加到vector容器中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [vector push_back()方法解析](https://blog.csdn.net/weixin_41763134/article/details/103627245)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [vector中的push_back(涉及到动态分配),resize,reserve,swap方法解析](https://blog.csdn.net/beibaoke910/article/details/115062728)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [C++ 中”emplace_back” 与 “push_back” 的区别](https://download.csdn.net/download/weixin_38548704/13997185)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文