读取文本文件中的特定行 [英] Reading a specific line in a textfile
本文介绍了读取文本文件中的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
有人可以帮我吗?
我想读取文本文件的第8行并将其放在textbox1中.
我知道阅读代码.
该代码是读取文本文件的方法:
Hi all,
can anyone help me please?
I want to read the 8th line of a text file and put it in textbox1.
I knew the code of reading.
This code is to read the text file:
FileStream^ fs = File::OpenRead( path );
但是如何读取第8行并将其转换为字符串?
提前谢谢.
重新标记为C ++/CLI
But how to read the 8th line and convert it to string?
Thanks in advance.
Retagged as C++/CLI
推荐答案
FileStream^ fs = File::OpenRead( path );
StreamReader^ sr = gcnew StreamReader( fs );
int count = 0;
String^ myLine;
while ( sr->Peek() >= 0 && count<8)
{
myLine = sr->ReadLine();
count++;
}
那应该做!
问候,
曼弗雷德(Manfred)
That should do it!
Regards,
Manfred
这篇关于读取文本文件中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文