C + + Primer 6.5.3 sessions

Source: Internet
Author: User
Tags sessions

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.