c++ - 错误 C2039 : 'chrono' : is not a member of 'std'

标签 c++ visual-studio-2015 c++-chrono

我正在使用 Visual Studio 2015 创建 Win32 项目。我尝试使用 chrono 库,但它说找不到它。我在控制台项目中使用 chrono 库测试了代码,但它在控制台项目上有效,但在 Win32 项目上无效。

#include <chrono>
...
using namespace std::chrono;

LocalDriveHeader header;
auto durnow = system_clock::now ().time_since_epoch ();

header.version = VERSION;
header.flags = 0x0000;
header.sector_size = sector_size;
header.early_time = chrono::duration_cast <milliseconds> (durnow).count ();
...

===EDIT===

是的,我确实包含了 chrono 标题。 该项目是带有预编译头文件的 Win32 项目。

c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(123): error C2039: 'chrono': is not a member of 'std'
1>  c:\program files (x86)\microsoft visual studio 14.0\vc\include\memory(1175): note: see declaration of 'std'
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(123): error C2871: 'chrono': a namespace with this name does not exist
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(126): error C2653: 'system_clock': is not a class or namespace name
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(126): error C3861: 'now': identifier not found
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(126): error C2228: left of '.time_since_epoch' must have class/struct/union
1>  c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(126): note: type is 'unknown-type'
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(131): error C2653: 'chrono': is not a class or namespace name
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(131): error C2065: 'duration_cast': undeclared identifier
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(131): error C2065: 'milliseconds': undeclared identifier
1>c:\users\eunbin\documents\visual studio 2015\projects\gamgeum\gamgeum\container.cpp(131): error C3536: 'durnow': cannot be used before it is initialized

最佳答案

您可能缺少 #include <chrono>在你的文件的顶部。你需要这个 #include为了访问 std::chrono命名空间。

关于c++ - 错误 C2039 : 'chrono' : is not a member of 'std' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39218154/

相关文章:

c++ - 在安装 NVIDIA CUDA 的同时使用 Intel OpenCL.dll

c++ - 如何在 Visual Studio 2015 中成功导出 C++ 项目模板?

c++ - 以特定方式获取计时时间

c++ - 分配作为默认初始化

c++ - 为什么 MinGW-w64 生成 32 位二进制文​​件?

c - VS2015 指针不断变化,对齐?

visual-studio-2015 - fopen 用于写入但不独占

c++ - 将 chrono::duration 类型转换为 std::tm 类型

c++ - 具有空定义的模板特化

c++ - 从一个或多个线程访问 std::list