本文介绍了有没有办法找出当前行的行号从文件中读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)是否有在C的方式,我们可以发现,我们从文件中读取行的行号。

2)我也想知道是否有另一种方式来找出行的文件比创建一个循环查找 EOF 其他总数在每行,直到它到达终点。


解决方案

Not unless you count the lines from the beginning of the file. You can't just position yourself arbitrarily in a file and know what line of text you're on, unless there is information in the file itself telling you, or you have created an index of sorts by a previous pass over the file. The usual approach is to accumulate a line count as you process lines from the file.

No. You must run through the whole the file and count the number of lines. Any external tools (such as wc) are doing exactly this. You need to be aware of different line-ending styles. Depending on what functions you are using to read the file, you may or may not have automatic newline translation.

这篇关于有没有办法找出当前行的行号从文件中读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:19