
Untitled
By: a guest on
Oct 3rd, 2014 | syntax:
C | size: 1.09 KB | views:
204 | expires: Never
#include <iostream>
#include <fstream>
int main(int argc, const char * argv[])
{
std::fstream file("text.bin",std::ios::binary | std::ios::out | std::ios::in );
double outArray[] = { 1.01234,2.01234,3.01234,4.01234,5.01234 };
if(file.is_open())
{
for(int i = 0; i < 5; i++)
file << outArray[i];
file.close();
}
file.open("text.bin");
if(file.is_open())
{
std::cout << "Original\t\t\tInput\n";
for(int i = 0; i < 5; i++)
{
/*
int value[sizeof(float)];
for (int b = 0; b < sizeof(float);b++)
{
file >> value[b];
}
float output = (value[0] << (3*8)) | (value[1] << (2*8)) | (value[2] << (1*8) )|
value[3];
*/
double output;
file >> output;
std::cout << outArray[i] << "\t\t" << output << std::endl;
}
file.close();
}
return 0;
}