使用intel TBB我正在尝试读取文件`serial',在文件的每一行上应用一个函数,并将结果保存到A类型的向量中。
struct A
{
long long time;
double price;
A(long long t, double p) : time(t),price(p){};
}
我创建了以下管道
vector<A> parallelFile(string fileName) {
ifstream fe(fileName);
string orden_fichero;
vector<A> ord;
parallel_pipeline( /*max_number_of_tokens=*/16,
make_filter<void,string>(
filter::serial,
[&](flow_control& fc)->string
{
getline(fe,orden_fichero);
if(fe.eof())
{
fc.stop(); // stop processing
return NULL;
}
else
{
return orden_fichero;
}
}
) &
make_filter<string,A>(
filter::parallel,
[](string p) ->A{
auto position = p.find('"',28);
auto price = stod(p.substr(position+2));
auto time = dateToMs2(p.substr(0,26).c_str());
return A(time, price);
}
) &
make_filter<A,void>(
filter::serial,
[&ord](A x) {ord.push_back(x);}
)
);
return ord;
}
int main()
{
vector<A> david=parallelFile("input.txt");
return 0;
}
其中dateToMs是一个返回long long的函数。
执行此pipline y会出现以下错误:
TBB Warning: Exact exception propagation is requested by application but the
linked library is built without support for it
terminate called after throwing an instance of 'tbb::captured_exception'
what(): basic_string::_M_construct null not valid
Aborted (core dumped)
我看到pipline的第一个过滤器读取了所有文件,错误出现在文件的末尾。
我做错了什么?
编辑:文件的每一行都有以下结构: dd-mm-yyyy hh:mm:ss.msmsms“CompanyName”ff.ff
其中: