std::chrono...hrono::day)(3)
π NAME
std::chrono::from_stream(std::chrono::day) β std::chrono::from_stream(std::chrono::day) (this is the C++ Standard Libary manual page, section (3), bestie π
)
okay so this is the from_stream overload that parses a std::chrono::day out of an input stream, and yes the NAME line really says the same thing twice. iconic of her, no notes.
β¨ Synopsis
Defined in header <chrono>
template< class CharT, class Traits, class Alloc =
std::allocator<CharT> >
std::basic_istream<CharT, Traits>&
from_stream( std::basic_istream<CharT, Traits>& is, const CharT* fmt,
(since C++20)
std::chrono::day& d,
std::basic_string<CharT, Traits, Alloc>* abbrev =
nullptr,
std::chrono::minutes* offset = nullptr );
So what does it do? It attempts to parse the input stream is into the std::chrono::day d according to the format string fmt. That's the whole assignment, fr fr.
It behaves as an UnformattedInputFunction, except that it has an unspecified effect on is.gcount(). After constructing and checking the sentry object, it attempts to parse the input stream is into d according to the format string fmt. If the parse fails to decode a valid day, is.setstate(std::ios_base::failbit) is called and d is not modified. π«Ά
If the format specifier %Z is used and successfully parsed, the parsed value is assigned to *abbrev if abbrev is not null. If the format specifier %z or a modified variant is used and successfully parsed, the parsed value is assigned to *offset if offset is not null.
π«Ά Parameters π«Ά
okay so here's who's who in this function's little friend group:
isβ the input stream, aka where we're reading from.fmtβ a format string (see below).dβ object to hold the parse result.abbrevβ if not null, pointer to an object that will hold the time zone abbreviation or name corresponding to the%Zspecifier.offsetβ if not null, pointer to an object that will hold the offset from UTC corresponding to the%zspecifier.
β¨ Format string β¨
The format string is literally zero or more conversion specifiers plus ordinary characters. Here's the vibe:
- Every ordinary character β excluding whitespace characters and the terminating null character β matches one identical character from the input stream, or causes the function to fail if the next character on the stream does not compare equal.
- Every whitespace character matches zero or more whitespace characters in the input stream.
Each unmodified conversion specifier begins with a % character followed by a character that determines the behavior of the specifier. Some conversion specifiers have a modified form in which an E or O modifier character is inserted after the % character. Some conversion specifiers have a modified form in which a width parameter given as a positive decimal integer (shown as N below) is inserted after the % character. Each conversion specifier causes the matched characters to be interpreted as parts of date and time types according to the breakdown below.
A character sequence in the format string that begins with a % but does not match one of the conversion specifiers below is interpreted as ordinary characters. iykyk π
Iffrom_streamfails to parse everything specified by the format string, or if insufficient information is parsed to specify a complete result, or if parsing discloses contradictory information,is.setstate(std::ios_base::failbit)is called. π
The following conversion specifiers are available:
%%β matches a literal%character.%nβ matches one whitespace character.%tβ matches zero or one whitespace character.
πΈ Year πΈ
%C,%NC,%ECβ parses the century as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%ECinterprets the locale's alternative representation of the century.%y,%Ny,%Ey,%Oyβ parses the last two decimal digits of the year. If the century is not otherwise specified (e.g. with%C), values in the range[69, 99]are presumed to refer to the years 1969 to 1999, and values in the range[00, 68]are presumed to refer to the years 2000 to 2068. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified commands%Eyand%Oyinterpret the locale's alternative representation.%Y,%NY,%EYβ parses the year as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is4. Leading zeroes are permitted but not required. The modified command%EYinterprets the locale's alternative representation.
π Month π
%b,%B,%hβ parses the locale's full or abbreviated case-insensitive month name.%m,%Nm,%Omβ parses the month as a decimal number (January is1). The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%Ominterprets the locale's alternative representation.
π¦ Day π¦
%d,%Nd,%Od,%e,%Ne,%Oeβ the Day crew.%d/%Ndparses the day of month as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified commands%Odand%Oeinterpret the locale's alternative representation.
π Day of the week π
%a,%Aβ parses the locale's full or abbreviated case-insensitive weekday name.%u,%Nuβ parses the ISO weekday as a decimal number (1-7), where Monday is1. The widthNspecifies the maximum number of characters to read. The default width is1. Leading zeroes are permitted but not required.%w,%Nw,%Owβ parses the weekday as a decimal number (0-6), where Sunday is0. The widthNspecifies the maximum number of characters to read. The default width is1. Leading zeroes are permitted but not required. The modified command%Owinterprets the locale's alternative representation.
β ISO 8601 week-based year β
In ISO 8601, weeks begin with Monday and the first week of the year must satisfy the following requirements:
- Includes January 4
- Includes first Thursday of the year
%g,%Ngβ parses the last two decimal digits of the ISO 8601 week-based year. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required.%G,%NGβ parses the ISO 8601 week-based year as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is4. Leading zeroes are permitted but not required.%V,%NVβ parses the ISO 8601 week of the year as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required.
π Week/day of the year π
%j,%Njβ parses the day of the year as a decimal number (January 1 is1). The widthNspecifies the maximum number of characters to read. The default width is3. Leading zeroes are permitted but not required.%U,%NU,%OUβ parses the week number of the year as a decimal number. The first Sunday of the year is the first day of week01. Days of the same year prior to that are in week00. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%OUinterprets the locale's alternative representation.%W,%NW,%OWβ parses the week number of the year as a decimal number. The first Monday of the year is the first day of week01. Days of the same year prior to that are in week00. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%OWinterprets the locale's alternative representation.
π Date π
%Dβ equivalent to"%m/%d/%y".%F,%NFβ equivalent to"%Y-%m-%d". If the width is specified, it is only applied to the%Y.%x,%Exβ%xparses the locale's date representation. The modified command%Exinterprets the locale's alternate date representation.
π§ Time of day π§
%H,%NH,%OHβ parses the hour (24-hour clock) as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%OHinterprets the locale's alternative representation.%I,%NI,%OIβ parses the hour (12-hour clock) as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%OIinterprets the locale's alternative representation.%M,%NM,%OMβ parses the minute as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%OMinterprets the locale's alternative representation.%S,%NS,%OSβ parses the second as a decimal number. The widthNspecifies the maximum number of characters to read. The default width is2. Leading zeroes are permitted but not required. The modified command%OSinterprets the locale's alternative representation.%pβ parses the locale's equivalent of the AM/PM designations associated with a 12-hour clock.%Rβ equivalent to"%H:%M".%Tβ equivalent to"%H:%M:%S".%rβ parses the locale's 12-hour clock time.%X,%EXβ%Xparses the locale's time representation. The modified command%EXinterprets the locale's alternate time representation.
π Miscellaneous π
Okay bestie, this is the grab-bag corner of the conversion specifiers β the leftovers that didn't fit anywhere else. They're still iconic though, don't sleep on them π«Ά
%c,%Ecβ Parses the locale's date and time representation β¨. And the modified command%Ec? That one interprets the locale's alternative date and time representation. Two flavours, same vibe π%z,%Ez,%Ozβ Parses the offset from UTC, in the format[+|-]hh[mm]. For example,-0430refers to 4 hours 30 minutes behind UTC, and04refers to 4 hours ahead of UTC π. The modified commands%Ezand%Ozparse the format[+|-]h[h][:mm]β that is, they require a:between the hours and minutes, and they make the leading zero for the hour optional. Fancy π%Zβ Parses the time zone abbreviation or name, and it's taken as the longest sequence of characters that only contains the charactersAthroughZ,athroughz,0through9,-,+,_, and/π₯. Greedy little thing, we love that for it.
π Return value π
No cap, the page literally just says this:
is
That's it. That's the whole return value section π bestie I cannot make it longer than the source gave us, so we're all just gonna sit with is and think about it π
π¦ See also π¦
parseβ parses a chrono object from a stream (C++20) (function template). Your bestie for turning text into actual chrono objects, periodt π
And that's the whole page, bestie β you officially know these conversion specifiers better than half the internet π§β¨ This one came from http://cppreference.com, dated 2024.06.10, and it's titled std::chrono...hrono::day)(3) πΈ Go parse something cute for me ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms