从ASCII文件中读取确切的行 [英] Read exact line from ASCII file

查看:146
本文介绍了从ASCII文件中读取确切的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

如果有人可以帮助我...我有带有统计数据的ASCII文件,并且只需从中读取一行,我该如何指示我想读哪行然后在另一个文件中打印... ???


示例:

文件:" xxx.ASCII"

其中的行:

(1,65)22/11/2007 12:00 {29 0 0} 0 5 85 69 55

(1,64)22 / 11/2007 12:00 {29 5 9} 5 6 2 7 9

(1,65)22/11/2007 12:00 {29 10 1} 58 6 98 5 45
(1,55)22/11/2007 12:00 {29 10 1} 55 56 59 22 21


我想从这个文件只读第三行并将其写入文件output.txt...我该怎么做...... ???我试图找到解决方案,但没有结果......我是C ++新手,所以请耐心等待......谢谢...... !!!

Hello!
If anyone can help me... I have ASCII file with statistic data, and need to read only one line from it, how can I indicate, which line I want to read and then print in another file...???

Example:
File: "xxx.ASCII"
Lines in it:
(1,65) 22/11/2007 12:00 {29 0 0} 0 5 85 69 55
(1,64) 22/11/2007 12:00 {29 5 9} 5 6 2 7 9
(1,65) 22/11/2007 12:00 {29 10 1} 58 6 98 5 45
(1,55) 22/11/2007 12:00 {29 10 1} 55 56 59 22 21

I want to read only third line from this file and write it to file "output.txt"... How can I do that...??? I tried to find solution, but without results... Im new in C++, so be patient... Thanks...!!!

推荐答案

HI .. 。


你可以使用fstream类逐行读取文件行,但我认为没有办法选择行然后得到它,我想你必须读行并在代码中使用计数器在等于3时采取特殊操作。


最好的问候
HI...

you can use fstream class to read the file lines,line by line, but i think there is no way to select the line and then get it, i think you must read lines and use counter in your code to take special action when it equal 3.

Best Regards


我会调用file.getline()三次并结果。 文件是你要创建的ifstream变量。


你不能使用>>操作员,因为那不会读完整行。
I would call file.getline() three times and go with the result. The "file" is an ifstream variable that you would create.

You can''t use the >> operator since that won''t read an entire line.


嗯......我想我没有告诉所有信息...... SRY ...... !!!我需要阅读的文件非常大......也许有可能使用行的开头或行中的其他交叉引用找到该行... ???


实际上关键字是:
(1,65) 22/11/2007 12:00 {29 10 1} 56 59 54 54

(1,65)是计数器的数量,{29 10 1}是一个元素...在ASCII文件中更多超过100个元素,并且每个元素超过100个计数器......而且从所有这些元素中我需要找到这个... ...
Mmm... I think I didn''t tell all information... SRY...!!! The file I need to read is VERY big... Maybe there is some possibility to find the line using the begin of line or other cross-reference from the line...???

Actually the keywords are:
(1,65) 22/11/2007 12:00 {29 10 1} 56 59 54 54

(1,65) is number of counter and {29 10 1} is one element... IN the ASCII file is more than 100 element''s and for each element is more than 100 counters... And from all of them I need to find exactly this one...


这篇关于从ASCII文件中读取确切的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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