很抱歉,这类似于家庭作业。但是,我无法使用 std::regex 解析天、月和年。我只是看不到缺少什么。
#include<iostream>
#include<string>
#include<vector>
#include<regex>
int main()
{
std::vector<std::string> series;
series.push_back("2013-02-01,54.87,55.20,54.67,54.92,2347600,54.92");
series.push_back("2013-01-31,54.74,54.97,53.99,54.29,3343300,54.29");
series.push_back("2013-01-30,54.84,55.35,54.68,54.68,2472800,54.68");
const std::regex date("(\\d{4})-(\\d{2})-(\\d{2})");
std::smatch dates;
for (unsigned int i = 0; i < series.size() ; i++)
{
if (std::regex_match(series[i], dates, date))
std::cout << dates[1] << "\t" << dates[2] << "\t" << dates[3] << std::endl;
else
std::cout << "No match!" << std::endl;
}
return 0;
}