C++:读写二进制文件到double数组,根据二进制数据量进行读取
生活随笔
收集整理的這篇文章主要介紹了
C++:读写二进制文件到double数组,根据二进制数据量进行读取
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼和數據在git
#include <math.h> #include <fstream> #include <iostream>#include <fstream> #include <iostream> #include <sstream> #include <string>using namespace std;//int readBinFile(std::string& filename, void*& bufPtr, int& pointNum, int pointDim)int main() {// open the file:std::streampos fileSize; //實例化fpos用于表示窄向流中的位置。std::ifstream file("cloud.bin", std::ios::binary);cout<<"file="<<!file<<endl;if (!file) {cout<<"!file"<<endl;return false;}// get its size://把文件的讀指針結尾位置向后移前個字節file.seekg(0, std::ios::end);fileSize = file.tellg();//把文件的寫指針從文件開頭向后移 0 個字節file.seekg(0, std::ios::beg);cout<<fileSize<<endl;int length=fileSize;double* f2 = new double[length];std::ifstream ifs("cloud.bin", std::ios::binary | std::ios::in);ifs.read((char*)f2, sizeof(double) * length);ifs.close();cout<<f2<<endl;/***for (int i = 0; i < length; i++){std::cout<<f2[i]<<std::endl;}***/return 0;}// read the data:總結
以上是生活随笔為你收集整理的C++:读写二进制文件到double数组,根据二进制数据量进行读取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VC包含目录、附加依赖项、库目录及具体设
- 下一篇: C++:读写二进制文件到double数组