问题描述
我有一个包含以下数据的txt文件:
ABCDE ...
1 546 456 89 456
2 6546 654 5646 6546
3 444 565 789 789
例如
我希望能够读取文件,并能够在变量中存储一整行,然后与下一行的数字进行比较,然后将最大的一行写入文件(该部分很容易)......我真的需要一个程序可以逐行读取每一行直到文件结尾并将它们存储到一个变量中......
我知道这是可能的,但我一直讨厌使用文件......休息很简单,但我从来没有设法使用文件...
我真的很想帮忙请求e
I have a txt file with data like this:
A B C D E ...
1 546 456 89 456
2 6546 654 5646 6546
3 444 565 789 789
for example
I would like to be able to read the file and be able to store one whole line in variables and then compare with the next line''s numbers and then write the biggest line to a file (that part is easy)...I really need a procedure that can read each line one by one until end of file and store them into a variable...
I know that is possible but i''ve always hated working with files...The rest is pretty easy, but i''ve never manage to work with files...
I would really like some help please
推荐答案
你好,
这里是alghorytham:
1)循环而指向文件的指针不能到达EOF(文件结尾);
2)使用getline,fgets或任何simmilar函数来提取单词行
3)循环后比较行
Savage
Hi,
here goes alghorytham:
1) Loop while pointer to file don''t reach EOF(end-of-file);
2) use getline,fgets or any simmilar function to extract sngle line
3) After loop compare lines
Savage
ok ...我理解你写的是什么,但是使用getline如何将包含各种变量的行分成单个变量???
ok...i understand what you wrote, but using getline how can i seperate the line which contains various variables into the individual variables???
这篇关于C中的Txt数据文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!