C 11:现代g上的“put_time不是std的成员”

weixin_38048154 2019-09-12 02:17:03
我在新编译器上遇到了一个老问题.尝试使用std :: chrono打印当前时间时收到以下错误: src/main.cpp:51:30: error: ‘put_time’ is not a member of ‘std’ std::cout << std::put_time(std::localtime(&time), "%c") << "\n\n"; ^~~ 违规片段没什么特别之处: #include <chrono> ... auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::cout << std::put_time(std::localtime(&time), "%c") << "\n\n"; 这看起来非常像GCC 4.x系列中返回的错误,如同所引用的那样: > std::put_time implementation status in GCC?> Why does std::put_time not compile using multiple compilers?> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54354 这个理论唯一的问题是我的GCC是现代的: $g++ --version g++ (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1) Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 我还检查了我的应用程序是否链接到相应的库: $ldd build/myapp ... libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fde97e7b000) libc.so.6 => /lib64/libc.so.6 (0x00007fde97595000) 最后,我的编译标志中没有任何异国情调: g++ -g -Wall -Werror -std=c++11 -Wno-sign-compare src/main.cpp -c -o obj/main.o 我能想到检查的一切都表明这应该有效.那么,总之,给出了什么?
...全文
514 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38072110 2019-09-12
  • 打赏
  • 举报
回复
问题是你包含了错误的标题. std :: put_time在< iomanip>中声明,而不是< chrono>. Also, it is not complaining about any of the other time operations such as std::localtime and to_time_t. std :: localtime在< ctime>中声明.

473

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧