gpt4 book ai didi

c++ - 无法解析 cc1plus : error: unrecognized command line option "-std=c++11"

转载 作者:行者123 更新时间:2023-11-27 22:56:47 28 4
gpt4 key购买 nike

我尝试用“g++ -std=c++11 -o w w.cpp”编译下面的程序并得到错误“cc1plus:错误:无法识别的命令行选项”-std=c++11“”。尝试使用 g++ -Dstd=c++11 -o w w.cpp 进行编译并得到以下一组错误:

In file included from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:41,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:39,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
from w.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stringfwd.h:42: error: expected ‘{’ before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stringfwd.h:42: error: expected unqualified-id before ‘++’ token
In file included from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:44,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/postypes.h:42,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:42,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:39,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
from w.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef:49: error: expected ‘{’ before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef:49: error: expected unqualified-id before ‘++’ token
In file included from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/postypes.h:42,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:42,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:39,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
from w.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:65: error: expected ‘{’ before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:65: error: expected unqualified-id before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:139: error: expected ‘{’ before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:139: error: expected unqualified-id before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:245: error: ‘::wcstold’ has not been declared
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:254: error: ‘::wcstoll’ has not been declared
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:255: error: ‘::wcstoull’ has not been declared
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:260: error: expected ‘{’ before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cwchar:260: error: expected unqualified-id before ‘++’ token
In file included from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:42,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:39,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
from w.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/postypes.h:70: error: expected ‘{’ before ‘++’ token
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/postypes.h:70: error: expected unqualified-id before ‘++’ token
In file included from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:40,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
from /usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
from w.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception:35: error: expected ‘}’ before end of line
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception:35: error: expected ‘}’ before end of line
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception:35: error: expected ‘}’ before end of line
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception:35: error: expected ‘}’ before end of line
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception:35: error: expected ‘}’ before end of line
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception:35: error: expected ‘}’ before end of line
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/exception:35: error: expected declaration before end of line

program- w.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int read_words(vector<string>& words, ifstream& in)
{
int i = 0;
while(!in.eof())
in >> words[i++];
return i-1;
}

int main()
{
ifstream ifp("names");

vector<string> w(500);
int number_of_words = read_words(w, ifp);
w.resize(number_of_words);

for(auto it : w)
cout << it << " ";
cout << endl;

map<string, string> wMap;

for(int i = 0; i < number_of_words;) {
wMap.insert(pair<string, string>(w[i], w[i+1]));
i += 2;
}

cout << "wMap.size()=" << wMap.size() << endl;
for(auto it = wMap.begin(); it != wMap.end(); it++)
cout << it->first << " " << it->second << endl;
}

海湾合作委员会版本:海湾合作委员会 (海湾合作委员会) 4.4.7 20120313 (红帽 4.4.7-3)g++ (GCC) 4.4.7 20120313 (红帽 4.4.7-3)

请帮我找出这个问题。

最佳答案

-std=c++11 仅受 GCC 4.7 及更高版本支持。对于其他版本,您可以使用 std=c++0x(自 GCC 4.3 起可用)。请参阅 GCC 关于 ‘C++0x/C++11 Support in GCC’ 的概述有关不同 GCC 版本中 C++11 支持的更多信息。

关于c++ - 无法解析 cc1plus : error: unrecognized command line option "-std=c++11",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092267/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com