How to delete the selected random data in vector?
#include <iostream>
#include <vector>
int main()
{
std::vector<int> shuf{ 1, 2, 3, 4, 5 };
int random = shuf[rand() % shuf.size()];
std::cout << random; // to get the random data in shu
std::find(shuf.begin(), shuf.end(), random);
shuf.erase(random);
for (int k = 0; k < shuf.size(); k++)
{
std::cout << shuf.at(k) << ' ';
break;
}
}
For example data in shuf
vector is { 1, 2, 3, 4, 5 }
then the random data for example is 4
so that the 4
will be deleted in vector, so the data in vector will be shuf{ 1,2,3,5 }
This is the error I got
no matching function for call to
'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)'
Aucun commentaire:
Enregistrer un commentaire