c++ - referencing a vector -


i have code

void split(vector<float> &fvec, string str) {     int place = 0;         for(int i=0; i<str.length(); i++)         {             if(str.at(i) == ' ')             {                 fvec.push_back(atoi(str.substr(place,i-place).c_str()));                 place=i+1;             }         }         fvec.push_back(atoi(str.substr(place).c_str())); } 

what im trying pass reference vector method splits string give floats without copying vector... dont want copy vector because containing 1000's of numbers.

is not possible pass vector reference or making stupid mistake?

if helps heres code im testing out with

int main (void) {     vector<float> fvec;     string str = "1 2 2 3.5 1.1";      split(&fvec, str);      cout<<fvec[0];      return 0; } 

it indeed possible. you're using wrong syntax. correct way :

split(fvec, str); 

what you're doing wrong because passes address of vector intended reference.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -