Skip to content

Instantly share code, notes, and snippets.

@Cvetomird91
Last active April 11, 2018 06:40
Show Gist options
  • Select an option

  • Save Cvetomird91/066734aa72688daac8fb16ed905edef3 to your computer and use it in GitHub Desktop.

Select an option

Save Cvetomird91/066734aa72688daac8fb16ed905edef3 to your computer and use it in GitHub Desktop.
#include <string>
#include <iostream>
#include <boost/regex.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
int main(int argc, char** argv) {
boost::regex date(R"((\d{2})\.(\d{2})\.(\d{4}))");
boost::smatch match;
boost::gregorian::date d;
std::ostringstream ss;
std::string filename(" of 18.05.2017.txt");
if (boost::regex_search(filename, match, date)) {
std::cout << match[0] << std::endl;
std::cout << match[1] << std::endl;
std::cout << match[2] << std::endl;
std::cout << match[3] << std::endl;
d = boost::gregorian::date(std::stoi(match[3]), std::stoi(match[2]), std::stoi(match[1]));
ss << d.day() << ' ' << d.month().as_number() << ' ' << d.year() << '\n';
std::cout << ss.str();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment