【问题标题】:C++ cannot open source file "time.h"C++ 无法打开源文件“time.h”
【发布时间】:2020-06-14 13:03:05
【问题描述】:

我正在尝试使用时钟来测量在 Visual Studio 2015 (x64) 中使用 C++ 在 Windows 上以 Debug x64 模式运行的程序的时间。

我在这些行中遇到错误:

#include <time.h>
#include <sys/timeb.h>

错误消息说:

无法打开源文件“time.h”

无法打开源文件“sys/timeb.h”

我必须添加什么路径才能包含目录才能修复此错误?

【问题讨论】:

  • 试试#include &lt;ctime&gt;
  • 另外,考虑
  • 我尝试了#include &lt;ctime&gt;,但出现了相同的消息:cannot open source file "ctime.h"。该程序曾经在不同的机器上运行,所以我认为它可以通过添加正确的路径来包含。
  • 不,和 Windows 10 x64 一样
  • 我找到了:docs.microsoft.com/en-us/cpp/c-runtime-library/reference/… 你应该接受这个答案,因为它解决了你的问题。

标签: c++ visual-studio include time.h


【解决方案1】:

你可以试试#include &lt;ctime&gt;

参考这个:http://www.cplusplus.com/reference/ctime/

time.h 使用的是 C 而不是 C++。

【讨论】:

  • 我尝试了#include &lt;ctime&gt;,但出现了同样的消息:cannot open source file "ctime.h"
  • 是的。 .h 我猜是 C 约定。现在使用 C++ 或多或少所有头文件都没有 .h。试试不带 .h
  • 好的#include &lt;ctime&gt;没有错误了,但是还是有这个错误:identifier "clock_t" is undefined
  • @HadiGhahremanNezhad 这是完全不同的问题,无法用提供的信息回答。
  • @HadiGhahremanNezhad "clock_t 应该是 ctime" 是的..?您是否阅读了我提供的文档链接?它在std 命名空间中,在ctime 标头中。
猜你喜欢
  • 1970-01-01
  • 2020-05-03
  • 2021-12-21
  • 2017-12-10
  • 1970-01-01
  • 2014-02-20
  • 2020-06-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多