gpt4 book ai didi

c++ - 无法将 std::string 转换为日期类型

转载 作者:太空狗 更新时间:2023-10-29 20:10:23 24 4
gpt4 key购买 nike

我正在使用 Howard Hinnant's date library并尝试转换 std::stringdate::year_month_day使用下面显示的一段代码。

#include "date.h"
#include <string>
#include <iostream>
#include <sstream>

int main()
{
std::string d = "2016-11-23";
std::istringstream in{d};
date::sys_days sd;
date::parse(in, "%F", sd);
date::year_month_day ymd = sd;
std::cout << ymd << '\n';
}

并且收到太多错误提示 ‘const class std::time_get<char>’ has no member named ‘get

In file included from convert_string_to_date.cpp:1:0:
date.h: In instantiation of ‘void date::detail::parse(std::basic_istream<_CharT, _Traits>&, const std::basic_string<CharT, Traits>&, date::local_time<Duration>&, std::basic_string<CharT, Traits>*, std::chrono::minutes*) [with CharT = char; Traits = std::char_traits<char>; Duration = std::chrono::duration<int, std::ratio<86400l, 1l> >; date::local_time<Duration> = std::chrono::time_point<date::local_t, std::chrono::duration<int, std::ratio<86400l, 1l> > >; std::chrono::minutes = std::chrono::duration<long int, std::ratio<60l> >]’:
date.h:4371:90: required from ‘void date::detail::parse(std::basic_istream<_CharT, _Traits>&, const std::basic_string<CharT, Traits>&, date::local_time<Duration>&, std::chrono::minutes*) [with CharT = char; Traits = std::char_traits<char>; Duration = std::chrono::duration<int, std::ratio<86400l, 1l> >; date::local_time<Duration> = std::chrono::time_point<date::local_t, std::chrono::duration<int, std::ratio<86400l, 1l> > >; std::chrono::minutes = std::chrono::duration<long int, std::ratio<60l> >]’
date.h:4447:42: required from ‘void date::parse(std::basic_istream<_CharT, _Traits>&, const std::basic_string<CharT, Traits>&, date::sys_time<Duration>&) [with CharT = char; Traits = std::char_traits<char>; Duration = std::chrono::duration<int, std::ratio<86400l, 1l> >; date::sys_time<Duration> = std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<int, std::ratio<86400l, 1l> > >]’
date.h:4649:59: required from ‘void date::parse(std::basic_istream<_CharT, _Traits>&, const CharT*, date::sys_time<Duration>&) [with CharT = char; Traits = std::char_traits<char>; Duration = std::chrono::duration<int, std::ratio<86400l, 1l> >; date::sys_time<Duration> = std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<int, std::ratio<86400l, 1l> > >]’
convert_string_to_date.cpp:12:27: required from here
date.h:4192:21: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, b, i-1);
^
date.h:4197:25: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, ymd, ymd+8);
^
date.h:4211:21: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, b, i-1);
^
date.h:4221:25: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, hm, hm+6);
^
date.h:4266:25: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, hm, hm+2);
^
date.h:4275:21: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, b, i-1-modified);
^
date.h:4322:21: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, b, i-1);
^
date.h:4343:17: error: ‘const class std::time_get<char>’ has no member named ‘get’
f.get(is, 0, is, err, &tm, b, e);

最佳答案

gcc 4.9 没有date.h 所需的完整time_get 支持。它适用于 gcc 5。

关于c++ - 无法将 std::string 转换为日期类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40150636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com