错误:“ string_view”不是“ std”的成员 [英] error: 'string_view' is not a member of 'std'
问题描述
我是C ++的新手。我在Windows10的visual-studio-code中编译了我的代码,带有2个类型为string和string_view的变量。字符串变量很好,但是string_view给出了错误。我还启用了configuration.json中的c ++ 17扩展并在vscode中编辑了configuration / ui文件。
i am new to c++. i compiled my code in visual-studio-code in windows10, with 2 variables of type string and string_view. string variable is fine, but string_view is giving errors.I also enable c++17 extension in configuration.json and edit configuration/ui file in vscode.
这是我的代码:=
#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();
^~
推荐答案
我找不到您代码中的任何错误。我在此处编译了代码(在此处复制代码并在编译之前选择语言C ++ 17),正在按预期工作。只需检查您正在运行的编译器是否支持C ++ 17功能即可。因为std :: string_view仅从C ++ 17起可用。
以便在Visual Studio中启用C ++ 17 在此处检查并在Visual Studio代码中遵循此。
I didn't find any bug in your code. I compiled your code here (Copy your code there and select the language C++17 before compiling) and it is working as expected. Just check the compiler which you are running supports C++17 features. Because std::string_view is only available from C++17 onwards. To enable C++17 in Visual studio check here and in Visual studio code follow this .
希望这样做将为您提供帮助。
Hope this will help you.
这篇关于错误:“ string_view”不是“ std”的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!