我正在尝试使用JetBrains CLion中的C++ 11语法编译一些代码,所以我希望禁用C++ 98模式.我按照StackOverflow问题的说明进行操作,但无法使其正常工作.
为了实现这个目标,我去了ALT + SHIFT + F10并-std=c++11在Program Arguments中传递了参数.
再次构建时,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)
^
Run Code Online (Sandbox Code Playgroud)
在代码中
Command::Command(std::vector<std::string> cmds)
{
for (std::string command : cmds)
{
addCommand(command);
}
}
Run Code Online (Sandbox Code Playgroud)
虽然我很确定问题不在我的代码中(IdeoneC++ 11与IdeoneC++ 98(4.8.1))
图片:CLion界面
我想象的是编译字符串(每条评论):
C:\cygwin64\bin\cmake.exe --build C:\Users\Zarthus\.clion10\system\cmake\generated\6dd8bed\6dd8bed\Debug --target testProject -- -j 4
Run Code Online (Sandbox Code Playgroud)
因此它似乎不包括我的内容.
我对其他JetBrains IDE没有很多经验,但据我所知,它们大致相同.
有人能够重现这个吗?我是否应该向JetBrains发送反馈意见,这可能不是100%工作(它仍然是早期发布版本)?或者我只是搞砸了,这里有用户错误吗?
谢谢!
我通常对我的 PHP 进行编码exit()是有原因的(即exit("You are not authorised to access this page");),但我最近才注意到这会发送退出代码0。
如何发送exit1 或更大的退出代码,同时仍然发送原因,但避免使用以下伪代码。
<?php
if ($user->isAdmin() !== true) {
echo "You are not authorised to access this page.";
exit(1);
}
Run Code Online (Sandbox Code Playgroud)
重现此问题的代码;尽管这可能并不是真的必要。(在 CLI 中,但在网页上也会发生同样的情况)
zarthus@zarth:~$ php -r "exit(1);"
zarthus@zarth:~$ echo $?
1
zarthus@zarth:~$ php -r "exit('a reason');"
zarthus@zarth:~$ echo $?
0
Run Code Online (Sandbox Code Playgroud)
我想这样做的原因是,当我使用exit它时,通常意味着程序已经进入了一个需要自我终止的阶段,因为出现了问题,或者未经授权。我想用它来监视脚本是否完全完成。