2016-07-21 82 views

回答

1

使用std::find()

#include <array> 
#include <iostream> 
#include <algorithm> 

int main() 
{ 
    std::array<int, 5> a1 { { 2, 3, 5, 7, 11 } }; 

    std::cout << "8 is in a1 ? " 
     << (a1.cend() != std::find(a1.cbegin(), a1.cend(), 8)) << std::endl; 

    std::cout << "7 is in a1 ? " 
     << (a1.cend() != std::find(a1.cbegin(), a1.cend(), 7)) << std::endl; 

    return 0; 
} 

可与每一个执行容器或支持begin()end()(或更好,cbegin()cend()

工作一个小例子