c++文件读写

  • fopen

FILE *pf = fopen(fn_license.c_str(),"w");
fprintf(pf, "%s\n", msg.c_str());
fclose(pf);
vector<double> orientation = { 1,0,0,0,1,0,0,0,1 };
memcpy(&cbct_volume->get_orientation()[0], orientation.data(), sizeof(double) * 9);
//orientation的内容拷贝到cbct_volume中


//读取图片像素
FILE *pf = fopen(cbct_file.c_str(), "rb");
PTR<vector<short>> tmp_volume_data(new vector<short>(size[0] * size[1] * size[2], 0));
fread(tmp_volume_data->data(), sizeof(short), size[0] * size[1] * size[2], pf);
cbct_volume->set_pixel(tmp_volume_data);
fclose(pf);


std::string ct_path = patient_dir + "\\ct\\" + ct_id + ".bin";
FILE *pf = fopen(ct_path.c_str(), "rb");
if (pf == NULL)
{
    LOGE(_("Load CT is failed!"))
    return false;
}
auto&& tmp_volume_data = vol->get_pixel();
if (!tmp_volume_data)
    tmp_volume_data = PTR_NEW(std::vector<short>);
tmp_volume_data->assign(size[0] * size[1] * size[2],0);
fread(tmp_volume_data->data(), sizeof(short), size[0] * size[1] * size[2], pf);
fclose(pf);
    PTR<std::vector<short>> vol_data;    
    std::string file_path = save_path + "\\" + file_name + ".bin";
    FILE* pf = fopen(file_path.c_str(), "wb");
    fwrite(vol_data->data(), sizeof(short), vol_data->size(), pf);
    fclose(pf);


    std::vector<short> data;
    std::string file_path = save_path + "\\" + file_name + ".raw";
    FILE* pf = fopen(file_path.c_str(), "wb");
    fwrite(&data[0], sizeof(short), data.size(), pf);
    fclose(pf);

参考网址;https://blog.csdn.net/qq_34097715/article/details/79970860

https://www.cnblogs.com/zhengfa-af/p/8145443.html

https://blog.csdn.net/weixin_30800807/article/details/97188984

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值