- 新增现代 C++ 教程的 Preface 章节,包括英文和中文版本 - 添加 C++ Primer 练习代码 - 新增 Learn C++ 教程的 C++ 开发简介章节 - 添加头文件解析文档 - 更新 mkdocs.yml,包含新教程的目录结构 - 修改项目设置,使用 Python 3.10环境
42 lines
1.0 KiB
C++
42 lines
1.0 KiB
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <iterator>
|
|
|
|
using std::begin; using std::end; using std::cout; using std::endl; using std::vector;
|
|
|
|
// pb point to begin of the array, pe point to end of the array.
|
|
bool compare(int* const pb1, int* const pe1, int* const pb2, int* const pe2)
|
|
{
|
|
if ((pe1 - pb1) != (pe2 - pb2)) // have different size.
|
|
return false;
|
|
else
|
|
{
|
|
for (int* i = pb1, *j = pb2; (i != pe1) && (j != pe2); ++i, ++j)
|
|
if (*i != *j) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int arr1[3] = { 0, 1, 2 };
|
|
int arr2[3] = { 0, 2, 4 };
|
|
|
|
if (compare(begin(arr1), end(arr1), begin(arr2), end(arr2)))
|
|
cout << "The two arrays are equal." << endl;
|
|
else
|
|
cout << "The two arrays are not equal." << endl;
|
|
|
|
cout << "==========" << endl;
|
|
|
|
vector<int> vec1 = { 0, 1, 2 };
|
|
vector<int> vec2 = { 0, 1, 2 };
|
|
|
|
if (vec1 == vec2)
|
|
cout << "The two vectors are equal." << endl;
|
|
else
|
|
cout << "The two vectors are not equal." << endl;
|
|
|
|
return 0;
|
|
} |