使用-std=c++14和-std=c++17冲突问题

 

有代码如下:

 1 #include <iostream>
 2 #include <string_view>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     std::string_view term_shared_view;
 9     return 0;
10 }
View Code

 

直接使用g++编译时:

user@devbox:~$ /toolchain/bin/x86_64-linux-gnu-g++ main.cpp 

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

main.cpp:9:7: error: string_view’ is not a member of ‘std

  std::string_view term_shared_view;

       ^~~~~~~~~~~

main.cpp:9:7: note: std::string_view’ is only available from C++17 onwards

user@devbox:~$ 

 

使用g++ -std=c++17编译时,顺利通过:

user@devbox:~$ /toolchain/bin/x86_64-linux-gnu-g++  -std=c++17  main.cpp 

user@devbox:~$ 

 

 

使用g++ -std=c++17 -std=c++14编译时,编译失败,-std=c++17不生效:

user@devbox:~$ /toolchain/bin/x86_64-linux-gnu-g++ -std=c++17 -std=c++14 main.cpp 

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

main.cpp:9:7: error: string_view’ is not a member of ‘std

  std::string_view term_shared_view;

       ^~~~~~~~~~~

main.cpp:9:7: note: std::string_view’ is only available from C++17 onwards

user@devbox:~$ 

  

 

 

 

 

 

 

posted on 2020-09-15 14:33  jueshiwuming  阅读(2971)  评论(0)    收藏  举报

导航