Visual Studio 2019: Identifier "time_t" undefined

Caffeinated Pizza 1 Reputation point
2021-02-25T06:02:26.027+00:00

Very simple header file:

#ifndef _PTIME_H
#define _PTIME_H
#pragma once

#include <ctime>


class PTime
{
public:
 PTime();
 ~PTime();

private:
 time_t now;
};

#endif

Is giving me an error Identifier "time_t" is undefined. How is this possible? I included the proper header file. Why is Visual Studio 2019 complaining about time_t?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,601 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Guido Franzke 2,196 Reputation points
    2021-02-25T06:53:01.28+00:00

    Hello,
    try to include <time.h> .
    Regards, Guido

    1 person found this answer helpful.

  2. WayneAKing 4,921 Reputation points
    2021-02-25T11:29:51.977+00:00

    Are you getting a compile error, or an Intellisense error?

    If the latter, try using the option to rescan the solution
    found under the Project menu.

    Sometimes when code is added bit by bit Intellisense does
    not pick up all of the changes automatically. Doing a Rescan
    forces it to process all of the code in its current state.

    • Wayne
    1 person found this answer helpful.