Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <map>
- #include <boost/xpressive/xpressive_static.hpp>
- #include <boost/xpressive/regex_actions.hpp>
- #include <boost/date_time/gregorian/gregorian.hpp>
- using namespace boost::xpressive;
- using namespace boost::gregorian;
- int main()
- {
- std::string input = "今日の日付は=YEAR=年=MONTH=月=DAY=日です。";
- // 本日の日付を取得
- date today = day_clock::local_day();
- // 取得した日付を文字列に変換
- std::string y = std::to_string(today.year());
- std::string m = std::to_string(today.month());
- std::string d = std::to_string(today.day());
- // 正規表現の対応表
- std::map<std::string, std::string> env;
- env["YEAR"] = y;
- env["MONTH"] = m;
- env["DAY"] = d;
- // = で始まって 大文字が1回以上続き = で終わる文字列を検索し、置き換える
- sregex envar = '=' >> (s1 = +upper) >> '=';
- std::string output = regex_replace(input, envar, boost::xpressive::ref(env)[s1]);
- // 結果を表示
- std::cout << output << std::endl;
- // → 今日の日付は2019年2月7日です。
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement