使用-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:~$ 

  

 

 

 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM