測試文字檔案大小

2021-07-30 12:53:45 字數 541 閱讀 3313

&1 源**說明

//測試文字名稱為example.txt

const char * filename = "example.txt";

long m,n;

ifstream file(filename, ios::in|ios::binary);

m = file.tellg();

file.seekg(0, ios::end);

n = file.tellg();

file.close();

cout <<"size of \" "<< filename<<" \" is "<< (n-m)<<" bytes. \n"<&2 函式說明

對於第乙個引數,可以是正負數值,正的表示向後偏移,負的表示向前偏移。而第二個引數可以是:

ios::beg:表示輸入流的開始位置

ios::cur:表示輸入流的當前位置

ios::end:表示輸入流的結束位置

&3 使用

讀取文字檔案

void ctestdlg onreadinfo cfile filewrite1 testwrite1.txt cfile modecreate cfile modewrite cfile filewrite2 testwrite2.txt cfile modecreate cfile modew...

寫文字檔案

textoper 文字檔案操作類 public class textoper 新建乙個檔案 public bool createfile string strpath,string strname else file.create strpath strname return true catch ...

文字檔案操作

1 文字檔案的寫入 建立檔案流 filestream filestream new filestream c myfile file.txt filemode.create 建立寫入器 streamwriter sw new streamwriter filestream 以流的方式寫入資料 sw....