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??
#include <iostream>
#include <fstream>
usingnamespace 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;
}
}