逐行读取文本文件并将每行保存在缓冲区中,而不管数据类型如何。 [英] Read a text file line by line and save each line in the buffer irrespective of data type.

查看:178
本文介绍了逐行读取文本文件并将每行保存在缓冲区中,而不管数据类型如何。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读取文本文件的一行,将其保存到缓冲区,通过udp套接字发送缓冲区然后再读取第二行等等。



到目前为止,因为我知道要从文本文件中读取的文本的数据类型,所以我一直在使用 fscanf()来读取每一行从文本文件。但现在我不知道数据类型,因此我不再可以使用此功能。有没有其他方法可以逐行阅读文本文件。



注意: 每行的长度可能会有所不同。

I want to read one line of the text file, save it to a buffer, send the buffer over a udp socket and then go and read the second line and so on..

So far, since I knew the data type of the text to be read from the text file, I had been using fscanf() to read each line from the text file. But now I don''t know the data types so it is not possible for me to use this function anymore. Is there any other way to read text file line by line.

Note: The length of each line may vary.

推荐答案

如果你以任何其他方式阅读文件的行,它们仍然是相同的行。它不会解决文件格式的问题。这个问题毫无意义。



例如,您可以使用 std :: istream :: getline

http://www.cplusplus.com/reference/istream/istream/getline/ [ ^ ]。



-SA
If you get "any other way" to read the lines of the files, they still will be the same lines. It won''t solve the problem of the file "format". The question makes no sense.

For example, you can use std::istream::getline:
http://www.cplusplus.com/reference/istream/istream/getline/[^].

—SA


这篇关于逐行读取文本文件并将每行保存在缓冲区中,而不管数据类型如何。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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