用C++读写dat文件,运行成功但实际上没有写进去,请问该如何解决这一问题?

如题,代码如下


```c++
#include <iostream>
#include <fstream>
#include <string>
using namespace std;


#define  img_w 1024  
#define  img_h 1024 //图片宽和高


int main()
{

    string input_file_name = "C:\\Shepp-Logan.dat";
    string output_file_name = "C:\\new_Shepp-Logan3.dat"; //文件存储路径,注意更改

    //数据读入
    fstream file_in;
    file_in.open(input_file_name, ios::in | ios::binary);
    if (!file_in)
    {
        cout << "open error!" << endl;
        exit(1);
    }
    float img_data[img_h][img_w];
    float tmp[1048576]; //开辟1024*1024的内存空间

    file_in.read((char*)tmp, 1048576 * sizeof(float));
    file_in.close();

    for (int i = 0; i < img_h; i++) {
        for (int j = 0; j < img_w; j++) {
            img_data[i][j] = tmp[i * 1024 + j];
        }
    }

    for (int i = 0; i < img_h; i++)
        for (int j = 0; j < img_w; j++)
            if (img_data[i][j] > 0.035)
            {
                img_data[i][j] = 1;
            }
            else img_data[i][j] = 0;

    fstream fileout1;

    fileout1.open(output_file_name, ios::out | ios::binary);

    fileout1.write((char*)img_data, 1048576 * sizeof(float));
    fileout1.close();
}

```

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。