Skip to content

Instantly share code, notes, and snippets.

@symroc
Created August 10, 2020 21:59
Show Gist options
  • Save symroc/c21c34dd491f2b6567244e0a3b5482f4 to your computer and use it in GitHub Desktop.
Save symroc/c21c34dd491f2b6567244e0a3b5482f4 to your computer and use it in GitHub Desktop.
How to read binary float(double) using STL only
#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