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
2
Answers
Answer to my own question: I added
"cmake.sourceDirectory:my_cmake_directory"
to.vscode/settings.json
, and in the command palette I ranCMake: Build
to build the target, then in command palette I ranDeveloper: 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".Did you try to #include <cstring> instead of "cstring" ? (assuming that "cstring" is not supposed to be in your includePaths as defined in your JSON).