skip to Main Content

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


  1. Chosen as BEST ANSWER

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


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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search