A simple task: to replace the date in the format "dd.mm.yyyy" by "dd month yyyy" On Perl I did it quickly, but on C ++.

std::string date = "12.10.2017"; std::regex monthSE(R"((?=\.)\d\d(?=\.))"); std::vector<std::string> months = { "", "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"}; std::smatch matched; std::regex_search(date, matched, monthSE); if (!matched.size()) { break; } std::string asd = matched[0].str(); int month = atoi(matched[0].str().c_str()); std::regex monthRE(R"(\.\d\d\.)"); date = std::regex_replace(date, monthRE, " " + months[month] + " "); 

    1 answer 1

    Do you need a cannon on the sparrows? If the format is strictly known - "дд.мм.гггг" - then the trivial will be enough

     vector<string> months = { "", " января ", " февраля ", " марта ", " апреля ", " мая ", " июня ", " июля ", " августа ", " сентября ", " октября ", " ноября ", " декабря "}; string date(string d) { return d.replace(2,4,months[stoi(d.substr(3,2))]); } int main() { cout << date("12.04.1961") << endl; cout << date("19.05.1963") << endl; }