어떻게 main()이 호출 될 때마다 변수의 값을 기억합니까?main의 C++ 저장 횟수가
즉,이 프로그램을 내가 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