First, I would like to express that I come to post my question, after a lot of searching on the internet, without finding a proper article or solution to what I'm looking for.
As mentioned in the title, I need to convert an ASCII file to Binary file.
My file is composed of lines, every line contain float separated by space.
I found that many people use c++ since it's more easy for this kind of task.
I tried the following code, but the generated file is so big.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char buffer;
ifstream in("Points_in.txt");
ofstream out("binary_out.bin", ios::out|ios::binary);
float nums[9];
while (!in.eof())
{
in >> nums[0] >> nums[1] >> nums[2]>> nums[3] >> nums[4] >> nums[5]>> nums[6] >> nums[7] >> nums[8];
out.write(reinterpret_cast<const char*>(nums), 9*sizeof(float));
}
return 0;
}
I found those 2 resources :
http://www.eecs.umich.edu/courses/eecs380/HANDOUTS/cppBinaryFileIO-2.html https://r3dux.org/2013/12/how-to-read-and-write-ascii-and-binary-files-in-c/
I appreciate if you have any others resources ?
lines in my ASCII input file are as below :
-16.505 -50.3401 -194 -16.505 -50.8766 -193.5 -17.0415 -50.3401 -193.5
Thank you for your time