CLion禁用C++98模式,支持C++11

CLion disable C++98 mode in favour of C++11

本文关键字:支持 C++11 模式 禁用 C++98 CLion      更新时间:2023-10-16

我正试图在JetBrains CLion中使用仅限C++11的语法编译一些代码,所以我希望禁用C++98模式。我按照这个StackOverflow问题的说明进行了操作,但无法使其正常工作。

为了实现这个目标,我使用ALT+SHIFT+F10并在程序参数中传递参数-std=c++11

在再次构建时,似乎仍然启用了C++98模式。

/cygdrive/c/Users/Zarthus/Documents/test/command.cpp: In constructor 'Command::Command(std::vector<std::basic_string<char> >)':
/cygdrive/c/Users/Zarthus/Documents/test/command.cpp:25:32: error: range-based 'for' loops are not allowed in C++98 mode
     for (std::string command : commands)
                                ^

在代码中

Command::Command(std::vector<std::string> cmds)
{
    for (std::string command : cmds)
    {
         addCommand(command);
    }
}

虽然我很确定这个问题不在我的代码中(IdeoneC++11与IdeoneC++98(4.8.1))

图片:CLion接口

我想象的是编译字符串(每个注释):

C:cygwin64bincmake.exe --build C:UsersZarthus.clion10systemcmakegenerated6dd8bed6dd8bedDebug --target testProject -- -j 4

所以它似乎不包括我的内容。

我对其他JetBrains IDE没有太多经验,但据我所知,它们基本上是一样的。

有人能复制这个吗?我是否应该向JetBrains发送反馈,说这可能不是100%有效的(它仍然是早期版本)?或者我只是把它搞砸了,这里有用户错误吗?

谢谢!

这是通过将add_definitions(-std=c++11)添加到CMakeLists.txt的末尾而不是在ALT+SHIFT+F10的命令行参数中来解决的。