admin管理员组文章数量:1122832
I have a simple function like this:
#include "cstring"
int main() {
std::string str = "abc";
std::size_t len = std::strlen(str.c_str());
return 0;
}
And the code runs fine. On the other hand, vscode shows an error that "namespace "std" has no member "strlen"C/C++(135)". I also tried to use strlen instead of std::strlen and it still cannot find the global C strlen in vscode. How should I fix this? I have my c_cpp_properties.json
as
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/Users/my_username/anaconda3/include/**",
"/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/**"
],
"defines": [],
"macFrameworkPath": ["/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c17",
"cppStandard": "c++11",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
my macOS version is 12.5, my clang version is 13.1.6 target arm64-apple-darwin21.6.0
I have a simple function like this:
#include "cstring"
int main() {
std::string str = "abc";
std::size_t len = std::strlen(str.c_str());
return 0;
}
And the code runs fine. On the other hand, vscode shows an error that "namespace "std" has no member "strlen"C/C++(135)". I also tried to use strlen instead of std::strlen and it still cannot find the global C strlen in vscode. How should I fix this? I have my c_cpp_properties.json
as
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/Users/my_username/anaconda3/include/**",
"/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/**"
],
"defines": [],
"macFrameworkPath": ["/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c17",
"cppStandard": "c++11",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
my macOS version is 12.5, my clang version is 13.1.6 target arm64-apple-darwin21.6.0
Share Improve this question asked yesterday DiveIntoMLDiveIntoML 2,5172 gold badges24 silver badges37 bronze badges2 Answers
Reset to default 0Did you try to #include <cstring> instead of "cstring" ? (assuming that "cstring" is not supposed to be in your includePaths as defined in your JSON).
Answer to my own question: I added "cmake.sourceDirectory:my_cmake_directory"
to .vscode/settings.json
, and in the command palette I ran CMake: Build
to build the target, then in command palette I ran Developer: Reload Window
then all the (incorrect) error messages go away, and the "build" button finally appears in the status bar to the right of "No Solution".
本文标签: visual studio codeVSCode cannot find strlen and stdstrlenStack Overflow
版权声明:本文标题:visual studio code - VSCode cannot find strlen and std::strlen - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736283888a1927118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论