我是 C++ 的新手。我在windows10的visual-studio-code中编译了我的代码,有2个类型为string和string_view的变量。string 变量很好,但是 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;
}
Run Code Online (Sandbox Code Playgroud)
错误是:=
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();
^~
Run Code Online (Sandbox Code Playgroud)