hello everyone!
i have a question about reading from a binary file.what if i want to start reading a file from a certain line of the file and end the reading to a certain line too?
is there a way to do this using an ifstream?

Recommended Answers

All 4 Replies

Read the file until you get to the 'certain start line'.
Then continue reading and doing what you need to do with each line.
When you reach the 'certain end line', stop reading.

thanks for your help
so i tried something like this
but i'm still not sure i got the whole idea:

long from = atoi(argv[2]); //argv[2] is the line number i want to begin //reading the file
	long to = atoi(argv[3]); //argv[3] is the line number i want to stop
	ifstream fp;
	streampos pos,finalpos;
	char line[LINESIZE];
	fp.open (argv[1]); //argv[1] is the name of the file
	if (!fp.is_open())
		throw "File not found ";
	pos = from;
	finalpos = to;
		catch(char d[LINESIZE]){

does this seem ok?i'm a bit confused..

does this seem ok?i'm a bit confused..

Not at all. Use my technique. It's simple. tkud's solution needs a lot more understanding of files than you have at this point in your programming.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.