Let's say I have a vector called numsVec, and I want to replace all number 10 in that vector with some random numbers in a range.
This is my way to do it:
auto it = std::find(numsVec.begin(), numsVec.end(), 10);
for(it; it != numsVec.end(); it++) {
*it = rand() % 9 + 1;
}
This worked and replaced all number 10 with some other random numbers in range 1 to 9; but I got this warning.
warning: statement has no effect [-Wunused-value]
for(it; it != numsVec.end(); it++)
I want to know why and how to get rid of that warning?
And by the way I wonder if I can use std::replace to approach the same. If yes, can someone provide a way to do it?
Thanks in advance.
Edit:
I saw the comment and people say the code I provided did not fit what I am trying to achieve. I might do the wrong way.
So allow me to simply ask how to replace an element with some random numbers. Because that is what I am trying to do.
Aucun commentaire:
Enregistrer un commentaire