B
bilbo2000
I am trying to read in a binary file which has the data stored as 32
bit float. I have been trying to figure out how to read this in as 32
bit but everytime I try to read it in the best I can do is a 8 bit
integer.
I was able to do this using a scripting language php, and found that
the data is stored in little endian format, so I would read 4
characters in and reverse the string and declare it a float and the
number would come out correct. I'm not sure exactly how to go about
this in C++ because in some cases I read a char and then print it out
I get '' or null.
This seems like a task that most C++ programmers would run into but I
have not really found any place that covers this.
int main()
{
const int unsigned DATA_SIZE = 401;
const int unsigned FIND_STRING = 99;
char data_array[DATA_SIZE];
char anotherstring[4];
char backstring[4];
std::ifstream data_file("firstdata.dat");
for (i = 0; i < DATA_SIZE - 1; ++i) {
assert(i >= 0);
assert(i < sizeof(data_array)/sizeof(data_array[0]));
data_file >> data_array;
int newdata = data_array;
std::cout << "This is the integer " << newdata << '\n';
}
return(0);
}
bit float. I have been trying to figure out how to read this in as 32
bit but everytime I try to read it in the best I can do is a 8 bit
integer.
I was able to do this using a scripting language php, and found that
the data is stored in little endian format, so I would read 4
characters in and reverse the string and declare it a float and the
number would come out correct. I'm not sure exactly how to go about
this in C++ because in some cases I read a char and then print it out
I get '' or null.
This seems like a task that most C++ programmers would run into but I
have not really found any place that covers this.
int main()
{
const int unsigned DATA_SIZE = 401;
const int unsigned FIND_STRING = 99;
char data_array[DATA_SIZE];
char anotherstring[4];
char backstring[4];
std::ifstream data_file("firstdata.dat");
for (i = 0; i < DATA_SIZE - 1; ++i) {
assert(i >= 0);
assert(i < sizeof(data_array)/sizeof(data_array[0]));
data_file >> data_array;
int newdata = data_array;
std::cout << "This is the integer " << newdata << '\n';
}
return(0);
}