簡體   English   中英

vc ++ 2010“數組不是std的成員”錯誤

[英]vc++ 2010 “array is not a member of std” error

以下C ++ 11代碼:

std::array<float, 3> A;

獲取錯誤消息:

array is not a member of std.

在Visual Studio中,單詞“array”為藍色,表示它是關鍵字。 這是CLI的擴展。 我以為我之前通過轉到Properties / C C ++ / Language並將“禁用語言擴展”設置為Yes來修復它 我還將“ 屬性/常規”設置為“ 無公共語言支持” 仍然沒有快樂。

如何將程序作為關鍵字忽略編輯器中array的可見性?

您需要包含<array>標頭。

即使使用帶有g ++的Ubuntu上的'array'指令,也可以重現此錯誤:

例如,這個C ++代碼:

#include <iostream>
#include <array>

using namespace std;
int main(){
    std::array<int, 5> myints;
    cout << myints.size();
}

編譯並運行如下:

g++ -o s s.cpp
./s

打印錯誤:

/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This 
file requires compiler and library support for the upcoming ISO 
C++ standard, C++0x. This support is currently experimental, and 
must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
s.cpp: In function ‘int main()’:
s.cpp:6:5: error: ‘array’ is not a member of ‘std’

解決方案:使用編譯器選項-std=c++0x編譯它:

g++ -o s s.cpp -std=c++0x
./s

然后程序正確打印:

5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM