C++ global variable to count calls to print()

Description

C++ global variable to count calls to print()

#include <string>
#include <iostream>

using std::string;

int print_count = 0;

void print_this(const string& s)
{
  print(s);/*from  w w w .  j  a va 2s .c  o m*/
}

void print_that(const string& s)
{
  print(s);
}

void print(const string& s)
{
  std::cout << s << std::endl;
  ++print_count;             // ADDED

}


int main()
{
  print_this("this");
  print_that("that");

  std::cout << "The print() function has been called a total of "
            << print_count << " times. " << std::endl;
}



PreviousNext

Related