vc 新增開啟檔案對話方塊並讀取檔案

2022-02-27 15:25:10 字數 686 閱讀 8296

1.建立開啟檔案對話方塊:  

cfiledialog dlg(true,//true是建立開啟檔案對話方塊,false則建立的是儲存檔案對話方塊

".txt",//預設的開啟檔案的型別

null,//預設開啟的檔名

ofn_hidereadonly | ofn_overwriteprompt,//開啟唯讀檔案

"文字檔案(*.txt)|*.txt|所有檔案 (*.*)|*.*||");//所有可以開啟的檔案型別

2.點開啟檔案對話方塊上面的確定鍵後

if(dlg.domodal()==idok)  

3.開啟檔案:file.open(m_path,cfile::moderead);

4.逐行讀取檔案:cstdiofile file;///可以逐行讀檔案的類

cstring   strline;    

while(file.readstring(strline))   //////將每行都放進strline字串裡

5判斷讀出來的字:

strline=「1|2|3|」;//要判斷的字串

int strindex1  = strline.find('|');//在字串中尋找「|」

cstring a[11];

if(-1 != strindex1)//只要找到「|」就不會返回-1 }

vc 新增開啟檔案對話方塊並讀取檔案

1.建立開啟檔案對話方塊 cfiledialog dlg true,true是建立開啟檔案對話方塊,false則建立的是儲存檔案對話方塊 txt 預設的開啟檔案的型別 null,預設開啟的檔名 ofn hidereadonly ofn overwriteprompt,開啟唯讀檔案 文字檔案 txt ...

VC新增開啟檔案對話方塊並讀取資料

1.建立開啟檔案對話方塊 cfiledialog dlg true,true是建立開啟檔案對話方塊,false則建立的是儲存檔案對話方塊 txt 預設的開啟檔案的型別 null,預設開啟的檔名 ofn hidereadonly ofn overwriteprompt,開啟唯讀檔案 文字檔案 txt ...

VC用對話方塊開啟檔案

void cmainframe onfileimport if m strcurrentdirpath.getlength strdir.getlength m strcurrentdirpath strdir position npos dlg.getstartposition cmediator...