我在 C++ 中有以下代码:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
int main ()
{
srand(time(0));
int noOfElements = 9;
for (int a = 0; a < 9; a++)
{
std::vector<int> poss;
for (int a = 1; a <= 9; a++)
poss.push_back(a);
for (int b = 0; b < 9; b++)
{
int random = rand() % 9;
std::cout << poss[random];
poss.erase(random);
noOfElements--;
}
std::cout << "\n";
}
}
然而,当我运行它时,它会返回:
error: no matching function for call to 'std::vector<int>::erase(int&)'
对于第 13 行。
为什么会这样,我该如何纠正?