未能解决cc1plus: error:无法识别的命令行选项“-std=c++11”

时间:2021-11-21 02:29:44

I tried compiling the below program with "g++ -std=c++11 -o w w.cpp" and geting the error " cc1plus: error: unrecognized command line option "-std=c++11" ". Tried compiling with g++ -Dstd=c++11 -o w w.cpp and getting the below set of errors:

我试着用“g+ -std=c++11 -o w”编译下面的程序。并得到错误“cc1plus: error: unrecognition command line选项”-std=c+ 11“。尝试使用g++ -Dstd=c++11 -o ww编译。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;
}

gcc Version: gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)

gcc版本:gcc (gcc) 4.4.7 20120313 (Red Hat 4.7-3) g+ (gcc) 4.4.7 20120313 (Red Hat 4.7-3)

Please help me to sought out this issue.

请帮助我找出这个问题。

2 个解决方案

#1


3  

-std=c++11 is only supported by GCC 4.7 and later. For other versions, you can use std=c++0x (available since GCC 4.3). See GCC’s overview on ‘C++0x/C++11 Support in GCC’ for more information about C++11 support in different GCC versions.

-std=c++11仅得到GCC 4.7及以后的支持。对于其他版本,可以使用std=c++0x(从GCC 4.3开始就可以使用)。有关不同版本的c++ 11支持的更多信息,请参阅GCC对“c++ 0x/ c++ 11在GCC中的支持”的概述。

#2


1  

You need to use -std=c++0x for gcc versions lower than 4.7

您需要使用-std=c++0x的gcc版本低于4.7。

#1


3  

-std=c++11 is only supported by GCC 4.7 and later. For other versions, you can use std=c++0x (available since GCC 4.3). See GCC’s overview on ‘C++0x/C++11 Support in GCC’ for more information about C++11 support in different GCC versions.

-std=c++11仅得到GCC 4.7及以后的支持。对于其他版本,可以使用std=c++0x(从GCC 4.3开始就可以使用)。有关不同版本的c++ 11支持的更多信息,请参阅GCC对“c++ 0x/ c++ 11在GCC中的支持”的概述。

#2


1  

You need to use -std=c++0x for gcc versions lower than 4.7

您需要使用-std=c++0x的gcc版本低于4.7。