题目:
改写6.3.2节练习6.33 中使用递归输出vector内容的程序,使其有条件地输出与执行过程有关的信息。
例如,每次调用时输出vector对象的大小。分别在打开和关闭调试器的情况下编译并执行这个程序。
#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
//#define NDEBUG
void print_vec(vector<int>::iterator beg, vector<int>::iterator end)
{
if(beg == end)
return;
#ifndef NDEBUG
cout << "vector size: " << end - beg << endl;
#endif // NDEBUG
cout << *beg << endl;
print_vec(beg+1, end);
}
int main()
{
vector<int> vec = {1,2,3,4,5,6,7,8,9};
print_vec(vec.begin(), vec.end());
return 0;
}