Приведённая ниже программка не работает,
а если я сам собираю float по байтику через bin_file.get(ch), или через bin_file.readsome(var,sizeof(float)) то всё хорошо.
Такое впечатление, что текущая позиция чтения не инкрементируется...
Может надо как-то задать ширину выравнивая или ещё чего.
Спасибо!
Код
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <conio>
using namespace std;
int main(int argc, char* argv[])
{
fstream bin_file(argv[1], ios_base::in | ios_base::binary);
if (bin_file==NULL)
{
cout << "Can't open input file!" << endl;
return -1;
}
for (int i=0; i<8; ++i)
{
float k1;
bin_file >> k1;
cout << "k1 = " << k1 << endl;
}
bin_file.close();
cout << "Press any key..." << endl;
getch();
return 0;
}
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <conio>
using namespace std;
int main(int argc, char* argv[])
{
fstream bin_file(argv[1], ios_base::in | ios_base::binary);
if (bin_file==NULL)
{
cout << "Can't open input file!" << endl;
return -1;
}
for (int i=0; i<8; ++i)
{
float k1;
bin_file >> k1;
cout << "k1 = " << k1 << endl;
}
bin_file.close();
cout << "Press any key..." << endl;
getch();
return 0;
}