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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM