我正试图编译这段包含
std::sample
的c++ 17代码,使用的是gcc版本6.3.0和下面的命令:g++ -std=gnu++17 -c main.cpp
。但我得到了这个错误:error: ‘sample’ is not a member of ‘std’
...#include <vector>
#include <algorithm>
#include <random>
int main()
{
std::vector<int> a{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector<int> b(5);
std::sample(a.begin(), a.end(),
b.begin(), b.size(),
std::mt19937{std::random_device{}()});
return 0;
}
gcc 6支持使用std::sample
吗?(在gcc 8.2.0下编译正常)
我在以下两个页面上找不到答案: