错误 C2039:'chrono':不是 'std' 的成员
error C2039: 'chrono': is not a member of 'std'
我正在使用 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 ();
...
===编辑===
是的,我确实包含了 chrono header。
该项目是 precompiled-header.
的 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
命名空间。
我在预编译头中添加了#include <chrono>
。
我不知道为什么将 #include <chrono>
添加到实际源中会导致问题...
我的问题是 "chrono" 的包含语句在 "stdafx.h"
的包含语句之前
我自己刚刚遇到了这个。就我而言,我新添加了一个名为 "Time.h" 的文件到我的项目中,这导致 name-collision 包含在 MSVC 的 STL 中的内部 header。奇怪的是,它以你描述的方式表现出来。重命名该文件修复了它。
我正在使用 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 ();
...
===编辑===
是的,我确实包含了 chrono header。 该项目是 precompiled-header.
的 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
命名空间。
我在预编译头中添加了#include <chrono>
。
我不知道为什么将 #include <chrono>
添加到实际源中会导致问题...
我的问题是 "chrono" 的包含语句在 "stdafx.h"
的包含语句之前我自己刚刚遇到了这个。就我而言,我新添加了一个名为 "Time.h" 的文件到我的项目中,这导致 name-collision 包含在 MSVC 的 STL 中的内部 header。奇怪的是,它以你描述的方式表现出来。重命名该文件修复了它。