Created
August 10, 2020 21:59
-
-
Save symroc/c21c34dd491f2b6567244e0a3b5482f4 to your computer and use it in GitHub Desktop.
How to read binary float(double) using STL only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <vector> | |
#include <string> | |
std::string current="your file here"; | |
std::ifstream infile; | |
std::vector<float> n; | |
std::vector<std::vector<float>> nums; | |
infile.open(current,std::ios::binary | std::ios::in); | |
infile.seekg(0,std::ios::end); | |
const int length=infile.tellg()/sizeof(float); | |
n.resize(length); | |
infile.seekg(0,std::ios::beg); | |
infile.read(reinterpret_cast<char *>(n.data()),n.size()*sizeof(float)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment