C++ 保存读取二进制

一、保存二进制

#include <iostream>
#include <fstream>

int main(){
    float* output = new float[100]();
    ofstream fout("test.bin", ios::binary);
    fout.write((char *)(&output[0]), sizeof(float)); 
    fout.close();
    return 0;
}

二、读取二进制

void Read()
{
    string str = "test.bin";
    float* freadbufs = new float[100];
    std::ifstream ifs(str, std::ios::binary);
    ifs.read((char*)freadbufs , sizeof(float) * 100);
    ifs.close();
    //delete freadbufs;
}

 

posted @ 2020-08-19 14:53  zebra_彬  阅读(1946)  评论(0编辑  收藏  举报