Clang 3.2 supports most of the language features added in the latest ISO C++ standard,C++ 2011. Use -std=c++11 or -std=gnu++11 to enable support for these features.
需要添加编译选项 -std=c++11 或 -std=gnu++11
mac os里面默认自带的gcc版本较低
建议还是升级下
没有升级gcc,改用system path下的clang++编译(用XCODE下载了command line tools)
结果居然编译过关了
指令
clang++ -stdlib=libc++ -std=c++11 main.cpp -o test
int main(int argc, const char * argv[]) { // insert code here... std::cout << "Hello, World!\n"; auto func = [](){ std::cout << "hahaha\n"; }; func(); std::vector<std::string> strs{"yahoo", "haha"}; for(auto const &data : strs){ std::cout<<data<<std::endl; } std::vector<std::string> strs2 = std::move(strs); for(auto const &data : strs2){ std::cout<<data<<std::endl; } std::unique_ptr<int> A(new int(3)); std::cout<<*A<<std::endl; print_comma_separated_list(32, "444", 34.564564, "lalamimilolipo"); return 0; }