From 55c99382eb984ec39fa932c342373fbf7319e5f3 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 7 Jul 2017 20:24:25 -0400 Subject: [PATCH] Updated Boost datetime Examples Translated (markdown) --- Boost-datetime-Examples-Translated.md | 51 +++++++++++++-------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/Boost-datetime-Examples-Translated.md b/Boost-datetime-Examples-Translated.md index 08e77f4..3520792 100644 --- a/Boost-datetime-Examples-Translated.md +++ b/Boost-datetime-Examples-Translated.md @@ -291,38 +291,35 @@ main() ``` ### Print Month +```c++ +#include "date.h" +#include - #include "date.h" - #include - - int - main() +int +main() +{ + using namespace date; + try { + std::cin.exceptions(std::ios::failbit); std::cout << "Enter Year: "; - int yi, mi; - std::cin >> yi; + year y; + std::cin >> parse("%Y", y); std::cout << "Enter Month(1..12): "; - std::cin >> mi; - try - { - using namespace date; - auto ym = year(yi)/mi; - if (!ym.ok()) - throw std::runtime_error("Bad year or month: " - + std::to_string(yi) + "/" + std::to_string(mi)); - auto wd = weekday{ym/1}; - auto endOfMonth = (ym/last).day(); - for (auto d = 1_d; d <= endOfMonth; d += days{1}, wd += days{1}) - std::cout << ym.year() << '-' << ym.month() << '-' - << d << " [" << wd << "]\n"; - } - catch (const std::exception& e) - { - std::cerr << "Error bad date, check your entry: \n" - << " Details: " << e.what() << '\n'; - } + month m; + std::cin >> parse(" %m", m); + auto ym = y/m; + auto endOfMonth = (ym/last).day(); + for (auto d = 1_d; d <= endOfMonth; d += days{1}) + std::cout << format("%F [%a]\n", ym/d); } - + catch (const std::exception& e) + { + std::cerr << "Error bad date, check your entry: \n" + << " Details: " << e.what() << '\n'; + } +} +``` ### Month Adding