Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <fstream>
- #include <iostream>
- #include <sstream>
- using namespace std;
- int main()
- {
- int fd, i, j, length, pos;
- int k, bytes_read;
- char buffer[100][16];
- ifstream Read;
- std::ostringstream oss;
- int current_position = 0;
- Read.open("from4to5", ios::binary);
- //Get the size of the file
- Read.seekg(0, ios::end);
- length = Read.tellg();
- Read.seekg(0, ios::beg);
- for(i=0; i<length; i++)
- {
- buffer[i][16] = '\0';
- }
- //Read the file in 16byte segments or eof(), whichever comes first
- //Testing the return condition of the function is preferred, as opposed to testing eof()
- while(Read.get(buffer[i], 17))
- {
- for(j=0; j<=16; j++)
- oss << buffer[i][j];
- cout << "Contents : " << oss.str() << endl;
- oss.seekp(0);
- bytes_read = bytes_read + 16;
- i++;
- }
- Read.clear();
- Read.close();
- sleep(15);
- Read.open("from4to5", ios::binary);
- Read.seekg(bytes_read);
- while(Read.get(buffer[i], 17))
- {
- for(j=0; j<=16; j++)
- oss << buffer[i][j];
- cout << "Contents : " << oss.str() << endl;
- oss.seekp(0);
- bytes_read = bytes_read + 16;
- i++;
- }
- Read.clear();
- Read.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement