您好,我有一个std::vector<std::string>
包含日期时间的内容,例如2011-03-23T12:23:32.123
我想生成 2 个int
20110323
和的向量122332123
。
我正在使用一个C++
名为 Rcpp 的库(我认为这不是真正的问题,但你永远不知道,所以我放了Rcpp
标签)
我做了这个可以完成这项工作,但速度很慢,我怎样才能加快速度?
Rcpp::List datetimeToInt(vector<string> datetimes){
const int N=datetimes.size();
Rcpp::IntegerVector date(N); //please consider those as std::vector<int>
Rcpp::IntegerVector time(N);
//this is what I want to speed up
for(int i=0; i<N; ++i){
datetimes[i].erase(std::remove_if(datetimes[i].begin(), datetimes[i].end(), not1(ptr_fun(::isdigit))), datetimes[i].end());
date[i] = atoi(datetimes[i].substr(0,8).c_str());
time[i] = atoi(datetimes[i].substr(8,12).c_str());
}
return Rcpp::List::create(_["date"]=date, _["time"]=time);
}