[英]Cannot set Eclipse Juno C++ with std=c++11
我有Eclipse Juno C ++(Build id:20120614-1722)。 我正在嘗試使用指令-std = c ++ 11或-std = c ++ 0x設置編譯器調用參數,但在編譯下面的代碼時。 Eclipse Juno中沒有“工具設置”(至少對於Mac),所以我不能進入“C / C ++ Build - > Settings - > Tool Settings”。 我的編譯器是GCC 4.8.0
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(void) {
vector<string> v = {"a","b","c"};
for(string s: v){
cout << s << endl;
}
return 0;
}
我有:
HelloWorld.cpp:16:33: error: could not convert ‘{"a", "b", "c"}’ from ‘<brace-enclosed initializer list>’ to ‘std::vector<std::basic_string<char> >’
HelloWorld.cpp:17:16: error: range-based ‘for’ loops are not allowed in C++98 mode
你可以按照我在這個答案中描述的步驟: Eclipse CDT C ++ 11 / C ++ 0x支持
一種可能性是,您的選項適用於工具鏈的錯誤部分。
我剛剛面臨同樣的問題。 請檢查您的項目是否具有自定義"makefile" ( *.mk )
。 如果它有“makefile”,請將以下內容放入“makefile”並編譯。
“LOCAL_CFLAGS:= -fexceptions -std = c ++ 0x -std = c ++ 11”
PS:LOCAL_CFLAGS用於編譯器標志,可以放入“xxx> Miscellaneous”。 坦率地說,如果您的項目沒有自定義“makefile”,我不知道如何解決它。 但是,Eclipse Juno字面上沒有上述人員的路徑。
您沒有看到工具設置的原因是因為在創建項目時,您應該選擇可執行文件而不是GNU Autotools
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.