English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++The list emplace_front function adds a new element to the beginning of the list, and the size of the container increases by one.
The following figure shows the working principle of this function:
void emplace_front(value_type val);
val: To insert the value at the beginning of the list.
It does not return any value.
Let's look at a simple example
#include#includeusing namespace std; int main() { listli; list::iterator itr; li.emplace_front("language"); li.emplace_front("programming"); li.emplace_front("a"); li.emplace_front("is"); li.emplace_front("C"); for(itr=li.begin();itr!=li.end();++itr) cout <<*itr << " "; return 0; }
Output:
C is a programming language.
In this example, the emplace_front() function adds a new different string to the list li, and the output becomes 'C is a programming language.'.