我該如何讓main()在每次被調用時記住一個變量的值?C++ store調用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;
將編號存儲在文件中。讓程序讀取它? –
將該號碼保存到磁盤。 – Chad