简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM