C++标准库函数std::euqal()功能比C字符的比较函数strcmp()强大和广泛。std::euqal()的功能是比较两个容器或者数组是否相同,数组的类型可以是char*、BYTE等常用基本数据类型。
当需要比较两个字符串或者字符数组是否相等时,可以用std标准库函数equal()函数替换strcmp。
1.1 std::euqal()函数声明和定义
/**
* @brief Tests a range for element-wise equality.
* @ingroup non_mutating_algorithms
* @param __first1 An input iterator.
* @param __last1 An input iterator.
* @param __first2 An input iterator.
* @return A boolean true or false.
*
* This compares the elements of two ranges using @c == and returns true or
* false depending on whether all of the corresponding elements of the
* ranges are equal.
*/
template<typename _II1, typename _II2>
inline bool
equal(_II1 __first1, _II1 __last1, _II2 __first2)
{
// concept requirements
__glibcxx_function_requires(_InputIteratorConcept<_II1>)
__glibcxx_function_requires(_InputIteratorConcept<_II2>)