write qvector in csv file
Solved
General and Desktop
-
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.
-
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; }