English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++ The emplace_back() function of the list inserts a new element at the end of the list, and the size of the list increases by one.
void emplace_back(value_type val);
val:The new value to be inserted at the end of the list.
It does not return any value.
Let's look at a simple example
#include <iostream> #include<list> using namespace std; int main() { listli={1,2,3,4}; list::iterator itr; li.emplace_back(5); for(itr=li.begin();itr!=li.end();++itr) cout<<*itr<<" "; return 0; }
Output:
1 2 3 4 5
In this example, the emplace_back() function adds a new element at the end of the list, namely5.
Let's look at a simple example
#include <iostream> #include<list> using namespace std; int main() { listli={'C','+}; list::iterator itr; for(itr=li.begin();itr!=li.end();++itr) std::cout << *itr; cout << '\n'; li.emplace_back('+'); for(itr=li.begin();itr!=li.end();++itr) std::cout << *itr; return 0; }
Output:
C+ C++
In this example, the emplace_back() function adds a new character at the end of the list, that is, " +