I wanted to use the unordered_map STL in c++, but as soon as I use the header, it gives me this error:
This file requires support for the compiler and library support for the ISO C++11 standard. This support is currently experimental and must be enabled with -std=c++11 or -std=gnu++11 compiler options.
I am attaching my code that I wanted to run, below. (Any inputs on the code are welcome too. thanks)
#include <iostream>
#include <unordered_map>
using namespace std;
class Node
{
public:
string a,b;
Node()
{
a="hello";
b="world";
}
};
int main ()
{
unordered_map<Node> mymap;
Node mynode;
mymap.insert(mynode);
std::cout << "myrecipe contains:" << std::endl;
for (auto& x: mymap)
std::cout << x.a << ": " << x.b << std::endl;
}
Edit: I got it to work by using the following commmand: g++ -std=c++11 [filename].cpp
Thanks for the help.
To see if your compiler has C++11 support, run it with just the --version option to get a print out of the version number. Do this for whichever compiler(s) you wish to use with Rosetta. Acceptable versions: GCC/g++: Version 4.8 or later.
Go to Tools Tab. Select Compiler Options.. Go to General tab. Check the checkbox named "Add following commands when calling the compiler", write this statement -std=c++11 , and then press OK.
Status of Experimental C++11 Support in GCC 4.8GCC provides experimental support for the 2011 ISO C++ standard. This support can be enabled with the -std=c++11 or -std=gnu++11 compiler options; the former disables GNU extensions.
C++17 features are available since GCC 5. This mode is the default in GCC 11; it can be explicitly selected with the -std=c++17 command-line flag, or -std=gnu++17 to enable GNU extensions as well.
First Option:
You can remove to error with -std=c++11
in compile time.
g++ -o binary yourFile.cpp -std=c++11
Second Option to integrate the development with c++11:
You can use a makefile with the CXXFLAGS set with -std=c++11
A makefile is a simple text file with instructions about how to compile your program. Create a new file named Makefile (with a capital M). To automatically compile your code just type the make command in a terminal. You may have to install make.
Here is the code :
CXX=clang++
CXXFLAGS=-g -std=c++11 -Wall -pedantic
BIN=prog
SRC=$(wildcard *.cpp)
OBJ=$(SRC:%.cpp=%.o)
all: $(OBJ)
$(CXX) -o $(BIN) $^
%.o: %.c
$(CXX) $@ -c $<
clean:
rm -f *.o
rm $(BIN)
It assumes that all the .cpp files are in the same directory as the makefile. But you can easily tweak your makefile to support a src, include and build directories.
The main answer to your question: specify -std=c++11
in your compile command.
Precisely which C++11 features are available will depend on your version of GCC. Here are two links that might help:
https://gcc.gnu.org/projects/cxx0x.html
http://wiki.apache.org/stdcxx/C++0xCompilerSupport
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With