Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. int main(int argc, const char * argv[])
  6. {
  7.     std::fstream file("text.bin",std::ios::binary | std::ios::out | std::ios::in );
  8.     double outArray[] = { 1.01234,2.01234,3.01234,4.01234,5.01234 };
  9.     if(file.is_open())
  10.     {
  11.         for(int i = 0; i < 5; i++)
  12.             file << outArray[i];
  13.        
  14.         file.close();
  15.     }
  16.    
  17.     file.open("text.bin");
  18.    
  19.     if(file.is_open())
  20.     {
  21.         std::cout << "Original\t\t\tInput\n";
  22.         for(int i = 0; i < 5; i++)
  23.         {
  24.             /*
  25.             int value[sizeof(float)];
  26.            
  27.             for (int b = 0; b < sizeof(float);b++)
  28.             {
  29.                 file >> value[b];
  30.             }
  31.            
  32.             float output = (value[0] << (3*8)) | (value[1] << (2*8)) | (value[2] << (1*8) )|
  33.             value[3];
  34.              */
  35.             double output;
  36.             file >> output;
  37.             std::cout << outArray[i] << "\t\t" << output << std::endl;
  38.            
  39.            
  40.            
  41.         }
  42.         file.close();
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement