c++ - 为什么错误: ‘locate_zone’ is not a member of ‘std::chrono’

标签 c++ c++11

代码:

//test.cpp
#include<chrono>
#include<string>
using namespace std;
int main(){
  string str("Europe/Oslo");
  std::chrono::locate_zone(str);
}

编译:

/tools/gcc/6.3.0/bin/g++ --std=c++11 test.cpp

输出:

test.cpp: In function ‘int main()’:

test.cpp:6:3: 错误:“locate_zone”不是“std::chrono”的成员 std::chrono::locate_zone(str); ^~~

最佳答案

您现在可以使用 Howard Hinnant's free, open source, time zone library 来体验这个 C++20 特性.

您需要将命名空间从 std::chrono 更改为 date:

#include "date/tz.h"
#include<chrono>
#include<string>
using namespace std;
int main(){
  string str("Europe/Oslo");
  date::locate_zone(str);
}

Some installation required.

Help is available.

关于c++ - 为什么错误: ‘locate_zone’ is not a member of ‘std::chrono’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50204405/

相关文章:

c++ - 将 std::string 转换为 std::chrono::duration

c++ - 给定一个元组,其中包含任意数量的包含不同类型的 vector ,我如何提取最小大小的 vector ?

C++ 通过 nullptrs 标记要在 STD 列表中删除的对象

c++ - clang 根据其重载之一拒绝带有尾随 decltype 返回类型的模板调用是否正确?

c++ - 我不小心没有使用 std::ref - 结果代码做了什么?

c++ - std::unordered_map - 使用 Lambda 专门化 KeyEqual

c++ - "Private memory"尽管对象被破坏,但捕获 bad_alloc 后未释放

c++ - GCC 左移严重错误

c++ - 为什么此代码在 Visual Studio 2012 的代码分析中发出缓冲区溢出警告 (C6385/C6386)?

c++ - 一个 CMake 目标可以链接到另一个库目标的 *shared* 版本吗?