int i = 0; vector<int> number; for (i = 0;i < 10;i++) { number.push_back(i + 1); } int value = 5; auto result = find(number.cbegin(), number.cend(), value); cout << "result = " << result; /*报错, 没有与这些操作数匹配的"<<"运算符...*/
解决方案
6
https://msdn.microsoft.com/en-us/library/h64454kx.aspx
Return Value
An input iterator addressing the first occurrence of the specified value in the range being searched. If no element is found with an equivalent value, returns last.
所以返回的是一个迭代器,如需cout,前置‘*’进行解引用
Return Value
An input iterator addressing the first occurrence of the specified value in the range being searched. If no element is found with an equivalent value, returns last.
所以返回的是一个迭代器,如需cout,前置‘*’进行解引用
7
是vector<int>::iterator这种类型
打印有问题
if (result == number.end())
{
cout << “No find” << endl;
}
else
{
cout << “Yes find result= ” << *result << endl;
}
打印有问题
if (result == number.end())
{
cout << “No find” << endl;
}
else
{
cout << “Yes find result= ” << *result << endl;
}
14
返回的是一个迭代器
Return value
Iterator to the first element satisfying the condition or last if no such element is found.
http://en.cppreference.com/w/cpp/algorithm/find
cout r的 << 没有重载对这种类型的输出
Return value
Iterator to the first element satisfying the condition or last if no such element is found.
http://en.cppreference.com/w/cpp/algorithm/find
cout r的 << 没有重载对这种类型的输出