public member function
template <class... Args> void emplace (Args&&... args);
Construct and insert element
Adds a new element at the top of the stack, above its current top element. This new element is constructed in place passing args as the arguments for its constructor.
This member function effectively calls the member function emplace_back of the underlying container, forwarding args.
- Arguments forwarded to construct the new element.
#include <iostream> // std::cin, std::cout
#include <stack> // std::stack
#include <string> // std::string, std::getline(string)
int main ()
mystack.emplace ("First sentence");
mystack.emplace ("Second sentence");
std::cout << "mystack contains:\n";
std::cout << mystack.top() << '\n';
One call to emplace_back on the underlying container.
The container and up to all its contained elements are modified.
Provides the same level of guarantees as the operation performed on the underlying container object.
- Insert element (public member function
- Remove top element (public member function