我是一名新手程序员,正在自学C++,使用的是Bjarne的书籍《C++11版本》。我在OS X El Cap上安装了Xcode命令行工具,并使用Coderunner 2进行编程。当使用初始化列表创建变量时,我的代码出现了错误。我认为这是因为Coderunner没有运行C++11。作为一个完全的新手,我不知道该怎么办。希望得到有用的建议。谢谢。
clang版本:Apple LLVM版本7.0.0(clang-700.0.72)
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;
}
I get the following error:
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.