Stack::emplace

Can anyone explain to me why this program cannot compile?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  // stack::emplace
#include <iostream>       // std::cin, std::cout
#include <stack>          // std::stack
#include <string>         // std::string, std::getline(string)

int main ()
{
  std::stack<std::string> mystack;

  mystack.emplace ("First sentence");
  mystack.emplace ("Second sentence");

  std::cout << "mystack contains:\n";
  while (!mystack.empty())
  {
    std::cout << mystack.top() << '\n';
    mystack.pop();
  }

  return 0;
}
Compiles fine for me. I aint no wizard. What errors do you get?
[Error] 'class std::stack<std::basic_string<char> >' has no member named 'emplace'.
I use Dev C++ compiler. But its not work on me.
closed account (D80DSL3A)
The emplace function is a c++11 feature, so enable support for this in your compiler.
If your compiler doesn't support c++11 use the push function instead.
http://www.cplusplus.com/reference/stack/stack/
Thanks fun2code now I knew what the writers meaning in this tutorial that tell about c++11 and c++98.
Thanks agains.
Topic archived. No new replies allowed.