Parsing an date/time string with std::get_time needs separators?

前端 未结 2 790
日久生厌
日久生厌 2020-12-20 17:18

Is a separator character required to parse a string using std::get_time? I can\'t find a reference to say that it is. I\'m trying to parse an ISO date/time string such as \"

2条回答
  •  时光取名叫无心
    2020-12-20 17:33

    According to the description of second parameter of std::get_time, separators are not required.

    The format string consists of zero or more conversion specifiers, whitespace characters, and ordinary characters (except %). Each ordinary character is expected to match one character in the input stream in case-insensitive comparison. Each whitespace character matches arbitrary whitespace in the input string. Each conversion specification begins with % character, optionally followed by E or O modifier (ignored if unsupported by the locale), followed by the character that determines the behavior of the specifier. The format specifiers match the POSIX function strptime()

    On my Mac, I use clang++(Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) ) to compile your code, and run the program, the output is: Sun Nov 5 12:34:56 2014. Acctually, I have gcc 4.8.2 installed, but it doesn't support the std::get_time and std::put_time. Then I search the implementation status for this function, and find that is not implemented in GCC 4.8.0

    It did fail in VS2013, after calling std::get_time, all the elements in t are just 0. Format specifiers don't do what's expected here on Windows. It's not your mistake.

提交回复
热议问题