Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrono literals in VS2015

The following code gives me a compile time error:

#include <chrono>

int main() {
    auto day = 24h;
    return 0;
}

Error C3688: invalid literal suffix 'h'; literal operator or literal operator template 'operator ""h' not found.

I'm trying this on Visual Studio 2015 Update 1, which according to this should work, so what's going on?

like image 905
Voo Avatar asked Jan 06 '23 16:01

Voo


1 Answers

The literals aren't in the global namespace. Add this:

using namespace std::chrono_literals;

Depending on the situation, you might also consider using:

using std::chrono::operator""h;

instead of importing every name from that namespace if you need more fine grained control.

like image 57
Kerrek SB Avatar answered Jan 18 '23 08:01

Kerrek SB