相关疑难解决方法(0)

错误:“string_view”不是“std”的成员

我是 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)

c++ visual-studio-code c++17

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

c++17 ×1

visual-studio-code ×1