⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex5_11.cpp

📁 Beginning Visual C++ 6源码。Wrox。
💻 CPP
字号:
// EX5_11.CPP
// Using a static variable within a function
#include <iostream>
using namespace std;

void record(void);  // Function prototype, no arguments or return value

int main(void)
{
   record();

   for(int i = 0; i<= 3; i++)
      record();

   cout << endl;
   return 0;
}

// A function that records how often it is called
void record(void)
{
   static int count = 0;
   cout << endl
        << "This is the " << ++count;
   if((count>3) && (count<21))             // All this....
      cout <<"th";
   else
      switch(count%10)                     // is just to get...
      {
         case 1: cout << "st";
                 break;
         case 2: cout << "nd";
                 break;
         case 3: cout << "rd";
                 break;
         default: cout << "th";            // the right ending for...
      }                                    // 1st, 2nd, 3rd, 4th, etc.
   cout << " time I have been called";
   return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -