2017-10-12 69 views
0

我面臨很多red crossesSymbol 'array' could not be resolved,代碼構建正常。Eclipse CDT無法解析std:array,std :: vector工作正常

#include <math.h> 
#include <array> 
#include <sstream> 
#include <string> 

static std::string printArray(std::array<double, 3> data) { 
    std::ostringstream strs; 
    strs << "(" << data[0] << " " << data[1] << " " << data[2] << ")"; 
    return strs.str(); 
} 

static std::string printVector(std::vector<double> data) { 
    std::ostringstream strs; 
    strs << "(" ; 
    for (const auto & value : data) 
     strs << value << " "; 
    strs << ")"; 
    return strs.str(); 
} 

的C++ 11特徵描述或here使用-std=c++11標誌C/C++ General -> Preposcessor Include Path, Macros etc. -> Porvides -> CDT GCC Built-in Compiler Settings下活化。

我的問題是沒有重複,因爲它適用於std::vector和其他C++ 11功能處理正確。

標題(#include <array>)可以通過按F3來解決。

我使用Eclipse的CDT版本:Neon.3版本(4.6.3)。

+0

我dont't得到任何錯誤在構建期間。我正在使用基於Makefile的構建。 – schorsch312

+0

@VT,我認爲這是不公佈的。我在那裏提出了建議的步驟。他們爲'std :: vector'工作,而不是'std :: array'。 – schorsch312

+0

在你爲了設置'-std = C++ 11'標誌而鏈接到的問題中的[接受的答案](https://stackoverflow.com/a/9135135/440558),它沒有提到「Preposcessor [sic ]包括路徑,宏等「 –

回答

0

問題是符號__cplusplus沒有值201103L。

要改變這一點,你需要

  • 編輯Project->Preferences->C/C++ General/C/C+ General->Paths and Symbols->GNU C++->Symbols加定義__cplusplus和設定值201103L setzen。

  • 下添加Window->Preferences->C/C++/Build/Settings/Discovery/CDT GCC Build-in Compiler Settings DAS論證 「-std = C++ 11」 明鏡命令行hinzufügen

  • 激活Project->Preferences->C/C++ General/C/C++ General/Path and Symbols->Providers所有條目下的複選框Use global provider shared between projects