[C++]求助,一个未知问题

代码:

#include <iostream>
#include <windows.h>
#include <ctime>
#include <cstdlib>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <bits/stdc++.h>
#include <set> 
#include <map>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <conio.h>
using namespace std ;
void xinghao()
{
    cout << "*****************" << endl ;
}
static string time()
{
    time_t t = time(NULL) ;
    char ch[64] = {0} ;
    strftime(ch , sizeof(ch) -1 , "%Y-%m-%d %H:%M:%S" , localtime(&t)) ;
    return ch ;
}
int main()
{
    ofstream log("CHJ.log" , std::ios::out | std::ios::app) ;
    log << "[" << time() << "]" << "opened" << endl ;
    log << "[" << time() << "]" << "loading" << endl ;
    
    int a = 0 ;
    int times ;
    ifstream dat("times.dat" , ios::in) ;
    dat >> times ;
    dat.close() ;
    ofstream data("times.dat" , ios::trunc | ios::out) ;
    if(times >= 1 && times < 4000000)
    {
        times++ ;
        data << times ;
    }
    else
    {
        data << "1" ;
    }
    data.close() ;
    
    log << "[" << time() << "]" << "the load was complete" << endl ;
    log << "[" << time() << "]" << "this procedure is from MCyouwan" << endl ;
    log << "[" << time() << "]" << "this procedure's version is rd-1,open times:" << times << endl ;
    xinghao() ;
    cout << "吃鸡游戏" << endl << "作者:MCyouwan" << endl ;
    xinghao() ;
    cout << "打开次数:" << times << endl ;

其中,输出的“打开次数”为4633604(初次),并且times.dat显示也为4633604。并且往后打开会不断+1(在这个数字的基础上)。
理想状态下应为:
初次打开:“打开次数”为1,times.dat为1
2次打开:“打开次数”为2,times.dat为2
以此类推
不知道为什么,它总会自动生成一个不知道是什么的数字,但程序无报错
求解答

乍看起来c++的cin、cout、ifstream、ofstream、istringstream、ostringstream在输入、输出上比c的scanf、printf、fscanf、fprintf、fread、fwrite、sscanf、sprintf简单,不用格式控制符!
但是不用格式控制符,输入输出恰好是你期望的格式的时候好说;等到输入输出不是你期望的格式的时候,你就会觉得还是用格式控制符更方便、更靠谱。
摒弃cin、cout、ifstream、ofstream、istringstream、ostringstream!
使用scanf、printf、fscanf、fprintf、fread、fwrite、sscanf、sprintf。