I'm new to programming, so I was wondering...
If I have an input file consisting of 100 lines, how do I read only up to line 50 and print out each line?
Thanks.
I'm new to programming, so I was wondering...
If I have an input file consisting of 100 lines, how do I read only up to line 50 and print out each line?
Thanks.
Please use 'fstream' to read your file and count each 'readline'. Each 'readline' means a full line which terminated with '\n'(return value without it). That should be useful.
Keep a counter, read lines from file till the counter less than 50 Something like this
counter = 0;
while((counter < 50) && (f.good())
{
getline(f,str);
cout<<str<<endl;
counter++
}
Note: this is not the full code, but guideline how to do.