STL Hello World
平时要有容器、算法、迭代器的思维模式 容器提供迭代器,算法使用迭代器 // 算法 int count(int* begin, int* end, int val){ int n = 0; while(begin != end){ if(*begin == val){ n++; } begin++; } return n; } int main() { // 容器 int arr[] = {1, 3, 0, 5, 1, 3, 1, 0}; // 迭代器 int* begin = arr; int* end = *(&arr + 1); int n = count(begin, end, 1); cout << "count: " << n << endl; return 0; }