我正在使用Visual Studio 2010并尝试使用std::copy_if函数,我想要复制所有满足谓词条件的值。例如:
struct comp
{
bool operator()(const int i) { return i == 5 || i == 7; }
};
int main()
{
array<int, 10> arr = { 3, 2, 5, 7, 3, 5, 6, 7 };
vector<int> res;
copy_if(arr.begin(), arr.end(), res.begin(), comp());
for(int i = 0; i < res.size(); i++)
{
cout << res[i] << endl;
}
return 0;
}
但是当我运行这段代码时,出现了“vector iterator not incrementable”错误。