c++vector

C++ compiler: 'class std::vector<std::vector<char> >' has no member named 'emplace_back'


I'm getting error from the compiler when coding C++. Here is my code:

#include <iostream>     
#include <algorithm>   
#include <typeinfo>
#include <string>
#include <vector>


std::vector< std::vector<char> > p(std::vector<char> v)
{
    std::vector< std::vector<char> > result;

    std::sort(v.begin(), v.end());
    do
    {
        result.emplace_back(v);
    }
    while(std::next_permutation(v.begin(), v.end()));

    return result;
}

and here is my error:

enter image description here

Any idea what is causing this?

I'm using Codeblocks 12.11, Windows 7 and my compiler is GNU GCC Compiler

Thnx for the assist :)

UPDATE:

In case somebody bumps into the same problem, here is the solution (in Codeblocks 12.11):

Go to: Settings --> Compiler --> Compiler settings --> Check the following checkboxes:

enter image description here

In addition to that remember to have a main-function in your code. Otherwise the compiler will give the following error:

enter image description here

The solution was given by the users who answered my post :)


Solution

  • Your compiler is not supporting C++11. The emplace_back member function of std::vector<T> has been added since C++11, as you can see.

    Depending on your compiler version, you probably just need some flags to tell the compiler to turn on C++11 features. You can do that on GCC and Clang with:

    -std=c++11 -stdlib=libc++
    

    Otherwise you might need to update your compiler version to a more recent one.