Is there a way to show a range of bytes in a file?

I am trying to display the first ten lines of a file that I just made. I know i can use the seekg and seekp functions to determine which byte I can access from the file. But I am having some trouble trying to display a RANGE of bytes in a file.

For example, i would like to display the content of a file that is within the byte range of 0 through 130. How can i use the seekg functions to display just that specific content of the file??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <fstream>

using namespace std;

int main ()
{
    fstream file;
    string name, line;

    cout << "Enter a name of a file to open it" << endl;
    getline (cin, name);

    file.open (name.c_str(), ios::in | ios::app);



    file.seekg(0, ios::beg);     //I am trying to make the range of bytes here
 
    file.seekg(130, ios::end);   // and here

    while (getline (file, line))
    {


        cout << line << endl;
    }

}
Last edited on
Have you considered putting your file contents in an array or is that not what you are going for? Otherwise, I found this
http://stackoverflow.com/questions/7830929/reading-only-specific-range-of-lines-in-a-text-file-c
I figured i could do that, but i'm just making sure if there's actually a way to determine a range of bytes in a file.

Or is it not possible?
Never mind, i find it easier using an array.
Topic archived. No new replies allowed.