It inserts the same double type value at the multiple locations inside a vector. The vector itself is resized as needed.
int InsertValue( vector<int> & vnIndices, double dValue )
int InsertValue( vector<int> & vnIndices, vectorbase& vVals )
If OK, it returns the new size of the vector. If error, it returns a negative number.
EX1
//Insert double value into double vector void vector_InsertValue_Ex1() { vector<double> vd = {1.1, 2.2, 3.3, 4.4, 5.3}; vector<int> vnIndices = {0, 4, 9}; double dVal = 38.5; vd.InsertValue(vnIndices, dVal); //Insert double type for (int ii = 0; ii < vd.GetSize(); ii++) { out_double("", vd[ii]); } // Output will be: 38.5, 1.1, 2.2, 3.3, 38.5, 4.4, 5.3, 0, 0, 38.5 }
EX2
//Insert int value into int vector void vector_InsertValue_Ex2() { vector<int> vnData = {1, 2, 3, 4, 5}; vector<int> vnIndices = {0, 4, 9}; int nVal = 100; vnData.InsertValue(vnIndices, nVal); //Change the type to double then change it back for (int ii = 0; ii < vnData.GetSize(); ii++) { out_int("", vnData[ii]); } // Output will be: 100,1,2,3,100,4,5,0,0,100 }
EX3
//Insert values into vector void vector_InsertValue_Ex3() { vector<double> vd = {1.1, 2.2, 3.3, 4.4, 5.3}; vector<int> vnIndices = {0, 4, 9}; vector<double> vVals = {1000, 2000, 3000}; double dVal = 38.5; vd.InsertValue(vnIndices, vVals); for (int ii = 0; ii < vd.GetSize(); ii++) { out_double("", vd[ii]); } // Output will be: 1000, 1.1, 2.2, 3.3, 2000, 4.4, 5.3, 0, 0, 3000 }
origin.h