Enabling `-std=c++14` flag in Code::Blocks

安稳与你 提交于 2019-11-28 19:42:57
Andreas DM

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:

  1. Download MinGW from here (particular build) or from official site to choose options
  2. Extract it to for example: C:\ (result will be C:\MinGW)
  3. Open Code::Blocks
  4. Go to Settings => Compiler.
  5. Go to “Toolchain Executables”.
  6. In the top field “Compiler’s installation directory”, change the directory to the one where you extracted the compiler. E.g C:\MinGW.
  7. Change all the necessary files under “Program Files” to match the files under C:\MinGW\bin:

  1. Before you hit “OK”, go to the leftmost tab “Compiler settings”.
  2. Select “Compiler Flags”.
  3. For simplicity, right-click in the list somewhere and select “New Flag”:

  1. Type in the following and click "OK", and tick the box of the flag you just created:

  1. 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;
}

May a humble newbie make one small suggestion? A small modification to test C++14 code, to allow resulting .exe file to be run independently of the IDE it was created in, slightly modified test program follows:

 #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;

     cout << "press enter to continue..." << endl;
     cin.ignore(10, '\n');
     cin.get();
 }

Thank you all, peace to all fellow coders, especially Igor Tandetnik.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!