c++ - Intellisense shows "no member named 'tm' in namespace std" - Stack Overflow

admin2025-05-02  0

The code compiles successfully, but IntelliSense displays error logs.

#pragma once

#include <iostream>
#include <string>
#include <ctime>
#include <chrono>
#include <map>

inline std::map<std::string, std::string> GetCurrentDateTime() {
    auto now = std::chrono::system_clock::now();
    auto in_time_t = std::chrono::system_clock::to_time_t(now);
    std::tm* localTime = std::localtime(&in_time_t);

    std::map<std::string, std::string> dateTimeMap = {
        {"year", std::to_string(localTime->tm_year + 1900)},
        {"month", std::to_string(localTime->tm_mon + 1)},
        {"day", std::to_string(localTime->tm_mday)},
        {"hour", std::to_string(localTime->tm_hour)},
        {"minute", std::to_string(localTime->tm_min)},
        {"second", std::to_string(localTime->tm_sec)}
    };

    return dateTimeMap;
}
{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/homebrew/lib/wx/include/osx_cocoa-unicode-3.2",
                "/opt/homebrew/include/wx-3.2",
                "/opt/homebrew/include/**"
            ],
            "defines": [
                "_FILE_OFFSET_BITS=64",
                "WXUSINGDLL",
                "__WXMAC__",
                "__WXOSX__",
                "__WXOSX_COCOA__"
            ],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-arm64",
            "compilerArgs": [
                "-std=c++17"
            ]
        }
    ],
    "version": 4
}
[{
    "resource": "/Users/admin/Library/CloudStorage/OneDrive/Development/Project/MealFinder/utils.h",
    "owner": "C/C++: IntelliSense",
    "code": "135",
    "severity": 8,
    "message": "no member named \"tm\" in namespace \"std\".",
    "source": "C/C++",
    "startLineNumber": 36,
    "startColumn": 10,
    "endLineNumber": 36,
    "endColumn": 12
}]
转载请注明原文地址:http://anycun.com/QandA/1746133242a92033.html