Advertisement
Guest User

halluc1nati0n

a guest
Dec 7th, 2009
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <fstream>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.  
  11.     int fd, i, oflag;
  12.     char buf[100];
  13.     ifstream Read;
  14.     int current_position = 0;
  15.     Read.open("from4to5", ios::binary);
  16.    
  17.     // The file has contents :
  18.     // BD8d3700indiaC#EBD6d4700godgeD3EBD9d1311badge3TE
  19.     while(!Read.eof()) {
  20.         Read.get(buf, 17);
  21.         cout << "child: # bytes read which were: " <<  buf << endl;  
  22.  
  23.     };
  24.     #
  25.     //Save current position in file
  26.     #
  27.     current_position = Read.tellg();
  28.     cout << current_position << endl;
  29.    
  30.    
  31.    
  32.     // seek to the position returned
  33.         Read.seekg(current_position);
  34.    
  35.     // File is modified ..
  36.     // Now, file has contents
  37.     // BD8d3700indiaC#EBD6d4700godgeD3EBD9d1311badge3TEBD6d1210clerk41EBD2d1100mayor47E
  38.    
  39.    
  40.     while(!Read.eof()) {
  41.     Read.get(buf, 17);
  42.     cout << "child: # bytes read which were: " <<  buf << endl;  
  43.    
  44.     };
  45.     Read.close();
  46.  
  47.    
  48.     // Output is :
  49.     // child: # bytes read which were: BD8d3700indiaC#E
  50.     // child: # bytes read which were: BD6d4700godgeD3E
  51.     // child: # bytes read which were: BD9d1311badge3TE
  52.     // child: # bytes read which were: BD6d1210clerk41E
  53.     // child: # bytes read which were: BD2d1100mayor47E
  54.     // 80
  55.    
  56.     // But rather it was intended to be only
  57.     // child: # bytes read which were: BD6d1210clerk41E
  58.     // child: # bytes read which were: BD2d1100mayor47E
  59.  
  60.     return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement