【发布时间】:2020-02-02 09:49:55
【问题描述】:
我是 C++ 新手。我在windows10的visual-studio-code中编译了我的代码,有2个类型为string和string_view的变量。字符串变量很好,但是 string_view 给出了错误。我还在 configuration.json 中启用了 c++17 扩展,并在 vscode 中编辑 configuration/ui 文件。
这是我的代码:=
#include<iostream>
#include<string_view>
using namespace std;
int main(){
string str="hello";
cout<<str<<endl;
std::string_view sv=" world";
auto result=str+sv.data();
return 0;
}
错误是:=
main.cpp: In function 'int main()':
main.cpp:7:12: error: 'string_view' is not a member of 'std'
std::string_view sv=" world";
^~~~~~~~~~~
main.cpp:7:12: note: 'std::string_view' is only available from C++17 onwards
main.cpp:8:23: error: 'sv' was not declared in this scope
auto result=str+sv.data();
^~
【问题讨论】:
-
你用的是什么编译器? Visual Studio Code 是一个文本编辑器。它不是用于编译和构建的 IDE。
-
我正在使用 g++。
标签: c++ visual-studio-code c++17