rca*_*pac 3 c++ initializer-list c++11 coderunner
我不熟悉Bjarne的书C ++ 11版本,对C ++进行编程和自学。我将Coderunner 2与OS X El Cap上安装的Xcode命令行工具一起使用。使用初始化列表创建变量时,出现以下代码错误。我相信Coderunner没有运行c ++ 11。我是一个完全新手,我不知道该为我的一生做什么。有益的建议表示赞赏。先感谢您。
clang版本:Apple LLVM版本7.0.0(clang-700.0.72)
#include <iostream>
#include <complex>
#include <vector>
using namespace std;
int main(int argc, char** argv)
{
double d1 = 2.3; //Expressing initialization using =
double d2{2.3}; //Expressing initialization using curly-brace-delimited lists
complex<double> z = 1;
complex<double> z2{d1,d2};
complex<double> z3 = {1,2};
vector<int> v{1,2,3,4,5,6};
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
2.2.2.2.cpp:9:11: error: expected ';' at end of declaration
double d2{2.3}; //Expressing initialization using curly-brace-delimited lists
^
;
2.2.2.2.cpp:12:20: error: expected ';' at end of declaration
complex<double> z2{d1,d2};
^
;
2.2.2.2.cpp:13:18: error: non-aggregate type 'complex<double>' cannot be initialized with an initializer list
complex<double> z3 = {1,2};
^ ~~~~~
2.2.2.2.cpp:15:15: error: expected ';' at end of declaration
vector<int> v{1,2,3,4,5,6};
^
;
4 errors generated.
Run Code Online (Sandbox Code Playgroud)
C ++ 11不是默认值。使用clang ++,以下是在C ++ 11中进行编译的必要条件:
-std=c++11 -stdlib=libc++
Run Code Online (Sandbox Code Playgroud)
在Coderunner 2中,您需要通过包含上述内容来修改与c ++有关的脚本。转到Coderunner>首选项,然后为Language选择C ++,然后单击'Edit Script':
您将在Coderunner中看到“ compile.sh”文件。修改第78行:
xcrun clang++ -x c++ -std=c++11 -stdlib=libc++ -lc++ -o "$out" "$
Run Code Online (Sandbox Code Playgroud)
修改第85行:
"$CR_DEVELOPER_DIR/bin/clang" -x c++ -std=c++11 -stdlib=libc++ -lc++ -o "$out" "${files[@]}" "-I$CR_DEVELOPER_DIR/include" "-I$CR_DEVELOPER_DIR/lib/clang/6.0/include" "-I$CR_DEVELOPER_DIR/include/c++/v1" "${@:1}"
Run Code Online (Sandbox Code Playgroud)
希望有帮助!谢谢Serge Ballesta向我指出正确的方向。