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 badges
Add a comment  | 

2 Answers 2

Reset to default 0

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).

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