天天看點

ubuntu下c++11的支援問題

使用g++ -o test test.cpp編譯程式c++程式時,由于使用了c++11的特性,是以在ubuntu下會報錯如下:

test.cpp: In function ‘int main()’:

test.cpp:11:11: error: ‘inter’ does not name a type

  for(auto inter=v.begin();inter!=v.end();inter++)

           ^

test.cpp:11:27: error: expected ‘;’ before ‘inter’

  for(auto inter=v.begin();inter!=v.end();inter++)

其實g++是支援c++11特性的,解決辦法就是加上編譯指令-std=c++11:

g++ -o test test.cpp -std=c++11