write qvector in csv file
-
wrote on 19 May 2020, 11:57 last edited by
Hey qt people,
I have a question to write csv file,
I have 3 QVector<double> a,b,c
a = (1,2,3,4)
b = (0,0,0)
c = (10.2)i want write a file csv like this:
1;0;10.2
2;0;
3;0;
4;;but the size is different, with the same size is simple :
int cpt=0; while(a.size!=cpt) { flux<<a<<";"<<b<<";"<<c<<endl }
but with different size how to do ?
-
Hey qt people,
I have a question to write csv file,
I have 3 QVector<double> a,b,c
a = (1,2,3,4)
b = (0,0,0)
c = (10.2)i want write a file csv like this:
1;0;10.2
2;0;
3;0;
4;;but the size is different, with the same size is simple :
int cpt=0; while(a.size!=cpt) { flux<<a<<";"<<b<<";"<<c<<endl }
but with different size how to do ?
@Albator said in write qvector in csv file:
but with different size how to do ?
use for-loop, take the max length from these 3 vectors and inside the loop check whether the current index is valid for each vector.
-
wrote on 19 May 2020, 12:24 last edited by VRonin
const QVector<double>* vects[] = {&a,&b,&c}; for(int i=0, maxI = std::max_element(sid::begin(vects), std::end(vects ),[](const QVector<double>* left, const QVector<double>* right)->bool{return left->size()<right->size();})->size();i<maxI;++i){ for(auto&& vec : vects){ if(i < vec->size()) flux<<vec->at(i) flux <<";" } flux<<endl; }
-
wrote on 19 May 2020, 14:11 last edited by
It works perfectly!
thanks for the help for the third or fourth time ahah!
3/4