首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误C2039:'chrono':不是'std‘的成员

错误C2039:'chrono':不是'std‘的成员
EN

Stack Overflow用户
提问于 2016-08-30 03:04:38
回答 4查看 9.3K关注 0票数 2

我正在使用Visual 2015创建Win32项目。我试过使用时间记录库,但它说找不到它。我在控制台项目中用时间同步库测试了代码,但它在控制台项目上工作,但在Win32项目上不起作用。

代码语言:javascript
运行
复制
#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===

是的,我确实包括了计时头。该项目是带有预编译头的Win32项目。

代码语言:javascript
运行
复制
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
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-09-03 04:46:21

我将#include <chrono>添加到预编译头中。我不知道为什么在实际的源代码中添加#include <chrono>会导致问题.

票数 4
EN

Stack Overflow用户

发布于 2016-08-30 03:08:15

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

票数 6
EN

Stack Overflow用户

发布于 2020-03-04 21:43:39

我刚才也遇到了这个问题。在我的例子中,我新添加了一个名为"Time.h“的文件到我的项目中,这导致了与MSVC的STL中包含的内部标头的名称冲突。奇怪的是,它表现在你描述的方式上。重命名那个文件修复了它。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39218154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档