practice 6.47: rewrite 6.3. Section 2 (page No. 205) a program that recursively outputs vector content is used to conditionally output information about the execution process. For example, the size of the vector object is output each time it is called. Compile and execute the program, respectively, when the debugger is turned on and off.
This requires adding new functionality ———— > conditionally outputting information about the execution process in the program that outputs the vector content in front of it.
In order to solve the problem easily, we use vector reference, the type of vector is string type, in the process does not change the size of the container.
After testing to get a phenomenon, the compiler will follow the #define DEBUG with #ifndef debug .... The sequence of the two is read, that is, who is in front of the position, and who reads. In order to run the instructions properly, we need to place the main () key function in front of the calling function.
The code is as follows:
1#include"stdafx.h"2#include <iostream>3#include <string>4#include <cctype>5#include <cstring>6#include <vector>,7 8 9 using namespaceStd////Declaration NamespaceTen voidPrintvec (vector<string>&,int);///Declare the function One A intMain () - { - #defineDEBUG////Add a preprocessing variable at the beginning of the main function thevector<string> Sub = {"Brother","Hello","can I give you two? " }; -Printvec (Sub,0); - return 0; - } + voidPrintvec (vector<string>& VEC,intCnt///Formal parameters: (container, Calculator) - { + A #ifndef DEBUG atcout << vec.size () << Endl;///output Vector Object size - #endif // ! DEBUG - - - - if(CNT! =vec.size ()) in { -cout << vec[cnt] <<Endl; toPrintvec (VEC, + +)CNT); + } - the}
C + + Primer 6.5.3 sessions