I am making a code in visual c++ to read ( and see in console )the floating numbers from a bin file, The binary file contains around 2.5 million floating point numbers.
int main(){
char* holder;
ifstream fin;
fin.open("male_16_down.bin",ios::binary|ios::in);
if(!fin){
cout<<" Error, Couldnt find the file"<<endl;
}
fin.seekg(0,ios::end);
long int file_size_bin=fin.tellg();
long int file_size=fin.tellg();
fin.seekg(0,ios::beg);
file_size=file_size/sizeof(float);
holder=new char[file_size_bin];
fin.read(holder,file_size*sizeof(float));
float data=(float)atof(holder);
cout<<data<<endl;
delete[] holder;
i know that 4 bytes for a float and 1 byte for char, this code outputs only one number that is 0,i believe atof()
converts only the first byte to the number, but i want the whole number to be seen and how can i see all the numbers in the binary file,
any help will be highly appreciated.
#include <fstream>
#include <iostream>
int main() {
float f;
std::ifstream fin("male_16_down.bin", std::ios::binary);
while (fin.read(reinterpret_cast<char*>(&f), sizeof(float)))
std::cout << f << '\n';
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With