如何使用fstream从第二行读取文本文件? [英] How do I read a text file from the second line using fstream?

查看:339
本文介绍了如何使用fstream从第二行读取文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让我的 std :: fstream 对象开始从第二行读取文本文件?

How can I make my std::fstream object start reading a text file from the second line?

推荐答案

使用getline()读取第一行,然后开始阅读流的其余部分。

Use getline() to read the first line, then begin reading the rest of the stream.

ifstream stream("filename.txt");
string dummyLine;
getline(stream, dummyLine);
// Begin reading your stream here
while (stream)
   ...

(更改为std :: getline(感谢dalle.myopenid.com))

(Changed to std::getline (thanks dalle.myopenid.com))

这篇关于如何使用fstream从第二行读取文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆