Mac OSX 10.7.4,Xcode 4.4.1,没有 <array> 头文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12516830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac OSX 10.7.4, Xcode 4.4.1, no <array> header file?
提问by Jefferson Hudson
I am writing a program that will use the array container of the C++ Standard Library to hold some objects. However, whenever I try to include the following line of code in my program:
我正在编写一个程序,它将使用 C++ 标准库的数组容器来保存一些对象。但是,每当我尝试在我的程序中包含以下代码行时:
#include <array>
I receive the following error at compile time:
我在编译时收到以下错误:
75-143-76-177:soft jeffersonhudson$ g++ mms.cpp -o mms
mms.cpp:5:17: error: array: No such file or directory
75-143-76-177:soft jeffersonhudson$
Commenting out the #include lets me compile just fine. Surely I am overlooking something simple? I have installed the "Command Line Tools" in Xcode, am I still missing something?
注释掉#include 让我编译得很好。当然,我忽略了一些简单的事情?我已经在 Xcode 中安装了“命令行工具”,我还缺少什么吗?
EDIT:
编辑:
I have found the location of array on my computer
我在我的电脑上找到了数组的位置
/usr/clang-ide/lib/c++/v1
knowing that, what should I do?
知道了,我该怎么办?
采纳答案by kennytm
<array>
is provided in C++11, you need to provide the -std=c++11
flag to enable it, and provide the -stdlib=libc++
flag for the corresponding library. But the g++ provided by Xcode is so old which doesn't have much support for C++11. Could you switch to clang?
<array>
C++11中提供了,需要提供-std=c++11
flag才能启用,并为-stdlib=libc++
对应的库提供flag。但是 Xcode 提供的 g++ 太旧了,对 C++11 没有太多支持。你可以切换到clang吗?
clang++ -std=c++11 -stdlib=libc++ mms.cpp -o mms
回答by justin
from the looks of it, you are not using LLVM's libc++, but GCC's libstdc++.
从它的外观来看,您使用的不是 LLVM 的 libc++,而是 GCC 的 libstdc++。
to use std::array
in the latter context, use:
要std::array
在后一种情况下使用,请使用:
#include <tr1/array>
if you want to use libc++ and C++11, then alter your compiler flags as KennyTM suggested (+1).
如果您想使用 libc++ 和 C++11,请按照 KennyTM 的建议(+1)更改您的编译器标志。