c中如何讀取文字檔案的最後一行

時間 2021-09-06 05:53:07

1樓:匿名使用者

兩種方法:

一行一行讀,讀到檔案尾,你就知道哪行是最好一行了。可以考慮使用system.io.file.readalllines()方法,返回值是字串陣列。

file.readalllines 方法 (system.io)https:

從流的末尾一個位元組一個位元組往前讀,讀到換行符以後,再從這個位置讀到檔案結尾。

2樓:匿名使用者

using system.io;

class program

while (newvalue != null);

}console.writeline(oldvalue);//輸出 ccccccccccc}/*

a.txt 檔案內容:

aaaaaaaaaa

bbbbbbbbb

ccccccccccc*/}

3樓:匿名使用者

讀取文字中的每一行沒問題吧。

申明一個變數儲存當前讀取的資料,當讀取結束了,該變數就是最後一行的讀取資料。

4樓:2009我們的

filestream fs = new filestream("1.txt", filemode.open, fileaccess.read);

streamreader sr = new streamreader(fs);

queuelast5pos = new queue();

last5pos.enqueue(0);

fs.seek(0, seekorigin.begin);

long pos = 0;

while (!sr.endofstream)

}} sr.close();

long poslist = last5pos.toarray();

for(int i=0; i< poslist.length; i++)

console.writeline(poslist[i].tostring());

if(poslist[poslist.length - 1] + 1 == fs.length)

else

fs.close();

求c語言讀取寫入文字檔案的函式實現

go陌小潔 c語言標準庫提供了一系列檔案i o函式用於檔案操作,比如fopen 用於開啟檔案 fread fwrite 用於讀寫檔案 fseek 用於設定操作位置等等,一般c語言教程上都有檔案i o一章,細緻內容,可以找本教科書學習一下。下面的示例,是向名為1.txt的檔案附加hello world...

python 讀取文字檔案 刪除裡邊的空行

趣園藝 def delblankline infile,outfile delete blanklines of infile infp open infile,r outfp open outfile,w lines infp.readlines for li in lines if li.spl...

關於c語言中文字檔案的逐行讀取的實現

小夏在深圳 若檔案不存在,則會建立該檔案,如果檔案存在,寫入的資料會被加到檔案尾,即檔案原先的內容會被保留。以附加方式開啟可讀寫的檔案。若檔案不存在,則會建立該檔案,如果檔案存在,寫入的資料會被加到檔案尾後,即檔案原先的內容會被保留。include main file fp fp fopen noe...