每次调用时如何让 main() 记住变量的值?
即,如果我第一次运行这个程序mainCallCounter = 0
,但是当我再次被调用时,我希望它增加计数器
#include <iostream>
using namespace std;
static int mainCallCounter = 0;
void outputMainCallCount()
{
cout << "Main was called" << mainCallCounter << "times." << endl;
}
int main()
{
outputMainCallCount();
mainCallCounter++;
return 0;