By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

STL jump to line

P: n/a
Hi. Is there any function like getline which loads specified line from
a text file? Something like getline(myfile, line, 10); where 10 means
10th line in the file.

Aug 6 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
ra*******@gmail.com wrote:
Hi. Is there any function like getline which loads specified line from
a text file? Something like getline(myfile, line, 10); where 10 means
10th line in the file.
No. It's too easy to write using 'getline' and 'ignore' to bother
putting it in the library, methinks.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 6 '07 #2

P: n/a
On Aug 6, 4:43 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
raven....@gmail.com wrote:
Hi. Is there any function like getline which loads specified line from
a text file? Something like getline(myfile, line, 10); where 10 means
10th line in the file.

No. It's too easy to write using 'getline' and 'ignore' to bother
putting it in the library, methinks.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
So how to code it?

Aug 6 '07 #3

P: n/a
ra*******@gmail.com wrote:
On Aug 6, 4:43 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>raven....@gmail.com wrote:
>>Hi. Is there any function like getline which loads specified line
from a text file? Something like getline(myfile, line, 10); where
10 means 10th line in the file.

No. It's too easy to write using 'getline' and 'ignore' to bother
putting it in the library, methinks.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

So how to code it?
Something like

std::istream& skip_lines(std::istream& is, std::size_t n)
{
while (is && n--)
is.ignore(
std::numeric_limits<std::istream::streamsize>::max (),
'\n');
return is;
}

...
std::ifstream myfile; // and open it
if (skip_lines(myfile, 10))
getline(myfile, line);

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 6 '07 #4

P: n/a
In article <11**********************@k79g2000hse.googlegroups .com>,
ra*******@gmail.com says...
Hi. Is there any function like getline which loads specified line from
a text file? Something like getline(myfile, line, 10); where 10 means
10th line in the file.
No -- to do something like that, you'd need an index of the text file
telling where each line begins. You can do that, but it's not built in.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Aug 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.