Shravan40 Shravan40 - 1 month ago 21
C++ Question

Can not convert std::string to date type

I am using Howard Hinnant's date library and trying to convert

std::string
to
date::year_month_day
using piece of code shown below.

#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';
}


And receiving too many error complaining about
‘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);

Answer

gcc 4.9 doesn't have the complete time_get support that date.h requires. It works on gcc 5.

Comments