Home > Software engineering >  from_stream not a member of std::chrono
from_stream not a member of std::chrono

Time:02-13

I am currently working on a small home project for some data processing in C . My input data contains timestamps, e.g. "2022-02-11T16:05:05 01:00". As I need to do some arithmetic on it (e.g. subtracting and adding minutes), I would like to convert this to a date/time format.

I came across this answer on Stack Overflow. I copy-pasted the exact same code into my code editor (Visual Studio 17.0.6), which produces buckets of errors, two of these being:

C2039   'sys_time': is not a member of 'std::chrono'
C2039   'from_stream': is not a member of 'std::chrono'

I then tried Wandbox with the latest GCC and Clang compilers, again with many errors (although the sys_time error has disappeared).

I haven't used C that much in the last couple of years, so I am not entirely familiar with all the additions to the recent versions. However, I see that the chrono library has been implemented in all of these compilers as part of the C 20 additions. Why do I keep getting these errors?

CodePudding user response:

There is a free, open source preview that I can recommend: Take a look at HowardHinnant

std::chrono::sys_time<std::chrono::microseconds> timestamp;
std::stringstream ss = foo();
ss >> date::parse("%Y-%m-%d %T", timestamp);

CodePudding user response:

This part of the chrono library is new with C 20, and has only been implemented by Visual Studio 19.x to date.

I was about to recommend my free open-source preview, but I see Orkhan has already done that for me. :-)

  •  Tags:  
  • c
  • Related