CLion禁用C ++ 98模式,有利于C ++ 11 [英] CLion disable C++98 mode in favour of C++11
问题描述
我想在JetBrains CLion中使用C ++ 11语法编译一些代码,所以我希望禁用C ++ 98模式。我按照此StackOverflow问题,但无法使其工作。
为了实现这个目标,我去了ALT + SHIFT + F10并传递了参数 -std = c ++ 11
在程序参数中。
再次构建时,仍然启用C ++ 98模式。
/cygdrive/c/Users/Zarthus/Documents/test/command.cpp:在构造函数'Command :: Command(std :: vector< std :: basic_string< char>>)'中:
/cygdrive/c/Users/Zarthus/Documents/test/command.cpp:25:32:错误:在C ++ 98模式中不允许基于范围的for循环
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:\cygwin64\bin\cmake.exe --build C:\Users\Zarthus\client10\system\cmake\generated\6dd8bed\6dd8bed\Debug --target testProject - -j 4
所以它不包括我的内容。 p>
我没有很多经验与其他JetBrains IDE,但从我可以告诉他们大致相同。
有没有人能够重现这个?我应该向JetBrains发送反馈,这可能不工作100%(它仍然是早期版本构建)?
谢谢!
这已经通过添加 add_definitions(-std = c ++ 11)
到 CMakeLists.txt
,而不是在ALT + SHIFT + F10的命令行参数。
I'm trying to compile some code using C++11 only syntax in JetBrains CLion, so I wish to disable C++98 mode. I followed the instructions accordance of this StackOverflow question, but am unable to get it working.
In order to achieve this goal, I went to ALT + SHIFT + F10 and passed the argument -std=c++11
in Program Arguments.
Upon building again, C++98 mode still seems to be enabled.
/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)
^
in the code
Command::Command(std::vector<std::string> cmds)
{
for (std::string command : cmds)
{
addCommand(command);
}
}
Whilst I'm fairly certain the issue lies not within my code (IdeoneC++11 versus IdeoneC++98 (4.8.1))
Image: CLion Interface
What I'd imagine is the compilation string (per comments):
C:\cygwin64\bin\cmake.exe --build C:\Users\Zarthus\.clion10\system\cmake\generated\6dd8bed\6dd8bed\Debug --target testProject -- -j 4
So it does not appear it includes my content.
I've not a lot of experience with other JetBrains IDE's, but from what I could tell they're mostly the same.
Is anyone able to reproduce this? Should I send feedback to JetBrains that this may not be working 100% (it's still an early release build)? Or am I just botching it up and is there an user error here?
Thanks!
This has been resolved by adding add_definitions(-std=c++11)
to the end of CMakeLists.txt
instead of in ALT+SHIFT+F10's command line arguments.
这篇关于CLion禁用C ++ 98模式,有利于C ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!