Rather than having three different results vectors - one each for float, int and string - just have one vector and put the data direct into this rather than into the three different and later on copying to yet another vector.
Replace these
withCode:vector<float> resultsarrayfloat; resultsarrayfloat.reserve(5000); vector<int> resultsarrayint; resultsarrayint.reserve(5000); vector<string> resultsarraystring; resultsarraystring.reserve(5000);
ReplaceCode:vector<results> resultsarray; resultsarray.reserve(5000); results oneres; ofstream ofs("results.csv");
withCode:resultsarrayfloat.push_back(t); resultsarrayfloat.push_back(y); resultsarrayfloat.push_back(z); resultsarrayint.push_back(indicator1position); resultsarrayint.push_back(indicator2position); resultsarrayint.push_back(trade1position); resultsarrayint.push_back(trade2position); resultsarrayint.push_back(numberofcells); resultsarrayint.push_back(indicator1value); resultsarrayint.push_back(indicator2value); resultsarrayint.push_back(trade1value); resultsarrayint.push_back(trade2value); resultsarrayint.push_back(tradevalue); resultsarraystring.push_back (headerarray[q]); resultsarraystring.push_back (headerarray[c]);
Then removeCode:oneres.t = t; oneres.y = y; oneres.z = z; oneres.indicator1position = indicator1position; .... etc resultsarray.push_back(oneres);
Code:vector<results> resultsarray; results oneres; //Open output file for the csv ofstream ofs("results.csv"); int m = 0; int n = 0; //Put some data into the result vector for test for (int l = 0; l < 200000; l++) { oneres.q = resultsarraystring[m]; oneres.c = resultsarraystring[m+1]; oneres.y = resultsarrayfloat[l]; oneres.z = resultsarrayfloat[l+1]; oneres.t = resultsarrayfloat[l+2]; oneres.indicator1position = resultsarrayint[n]; oneres.indicator2position = resultsarrayint[n+1]; oneres.trade1position = resultsarrayint[n+2]; oneres.trade2position = resultsarrayint[n+3]; oneres.numberofcells = resultsarrayint[n+4]; oneres.indicator1value = resultsarrayint[n+5]; oneres.indicator2value = resultsarrayint[n+6]; oneres.trade1value = resultsarrayint[n+7]; oneres.trade2value = resultsarrayint[n+8]; oneres.tradevalue = resultsarrayint[n+9]; resultsarray.push_back(oneres); m = m + 2; l = l + 2; n = n + 10; }




Reply With Quote