To compile your source code using C++14 in Code::Blocks, you, first of all, need to download and install a compiler that supports C++14 features.
Here’s how you can do it on Windows:
- Download MinGW from here (particular build) or from official site to choose options
- Extract it to for example: C: (result will be C:MinGW)
- Open Code::Blocks
- Go to Settings => Compiler.
- Go to “Toolchain Executables”.
- In the top field “Compiler’s installation directory”, change the directory to the one where you extracted the compiler. E.g C:MinGW.
- Change all the necessary files under “Program Files” to match the files under C:MinGWin:
- Before you hit “OK”, go to the leftmost tab “Compiler settings”.
- Select “Compiler Flags”.
- For simplicity, right-click in the list somewhere and select “New Flag”:
- Type in the following and click "OK", and tick the box of the flag you just created:
- Lastly, you need to specify the debugger path. Go to "Settings" => "Debugger", click "Default" on the left-hand side and enter the new full path of the executable:
Now, try to compile a program with C++14 features:
#include <iostream>
#include <string>
using namespace std;
auto main() -> int
{
auto add_two([](auto x, auto y){ return x + y; });
cout << add_two("I"s, "t"s) << " works!" << endl;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…