How do I enable C++11?

Hello, I have an issue with enabling C++11. In my homework, it says thag I have to start compiling the source file with "--std=c+11" on the command line. However, I don't know what this means exactly and when I try entering
--std=c+11, I get an error message saying that "--std is not recognized as an internal or external command, operable program, or batch file." What am I doing wrong?
You need one minus sign, not two.
-std=c++11
No, two minus-signs is a canonical GNU option, and is valid (but GCC accepts one minus-sign, too).

--std=c++11 is an option that the compiler needs to have passed to it on the command-line.

When you compile your code from the command line, you run the compiler program from the shell by typing the name of the program followed optionally by some options and some arguments. This is how every program works -- basically everything, unless you're on Windows.

Options start with a leading dash (or two, conventionally, if the option is longer than a single letter), and arguments don't start with a leading dash. (On Windows, it's often a leading slash /, but that's not conventional, so G++ sticks with the dash)

g++ my_file.cpp my_file2.cpp -lmy_library -oprogram

In the command-line invocation above, program arguments are the names of your files that G++ will compile, and options start with a dash. The first one is -l and the option's argument is "my_library" -- which tells g++ to link "my_library". The second one is -o and the option's argument is program, which tells g++ to create an executable file named "program".

You need to add the option --std=c++11 (not c+11) to the compiler's command line, which tells the compiler to use the STanDard language version called C++11.
g++ --std=c++11 your_source_code.cpp -oprogram

There are a lot of options you can pass to G++. Read the manual if you're curious.
Topic archived. No new replies allowed.