user2821630
user2821630

Reputation: 182

error C2039: 'chrono': is not a member of 'std'

I am using Visual Studio 2015 to create Win32 Project. I tried to use chrono library, but it says it cannot find it. I tested the code with chrono library in a console project, but it worked on the console project, but not on Win32 project.

#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===

Yes, I did included chrono header. The project is Win32 Project with precompiled-header.

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

Upvotes: 7

Views: 14966

Answers (4)

Keith Russell
Keith Russell

Reputation: 598

I just now encountered this myself. In my case, I had newly added a file named "Time.h" to my project, and that caused a name-collision with an internal header included by in MSVC's STL. Oddly, it manifested in the way you described. Renaming that file fixed it.

Upvotes: 5

The issue in my case was that the include statement for "chrono" was before the one for "stdafx.h"

Upvotes: 3

user2821630
user2821630

Reputation: 182

I added #include <chrono> into the precompiled header. I have no idea why adding #include <chrono> into the actual source caused problem...

Upvotes: 6

null1ng
null1ng

Reputation: 111

You may be lacking a #include <chrono> at the top of your file. You need this #include in order to have access to the std::chrono namespace.

Upvotes: 10

Related Questions