導航:首頁 > 版本升級 > mfctxt執行了但不寫文件

mfctxt執行了但不寫文件

發布時間:2024-03-16 13:13:16

1. MFC讀取txt文件

首先給edit控制項添加一個整形變數 num1, 代碼如下:

voidCMFCApplication2Dlg::OnBnClickedButton1()
{
//打開文件data.txt
FILE*pf=fopen("data.txt","r");

//讀取一個整數到Edit關聯的變數num1中
fscanf(pf,"%d",&num1);

//關閉文件
fclose(pf);

//更新變數num1的值到Edit中
UpdateData(FALSE);
}

2. VC++6.0mfc怎麼讀寫txt文件

先創建一個user.txt文檔;
然後在需要保存數據的地方打開user。txt文檔,進行寫操內作,最容後關閉。
//對文件進行寫操作

CFile mFile(_T("user.txt "), CFile::modeWrite|CFile::modeCreate);

mFile.Write(sRead,2);

mFile.Flush();

mFile.Close();

3. mfc 怎麼完成對txt文件的讀取和寫入

我寫了一個。

界面一個文本框兩個按鈕,文本框關聯一個CString型變數m_Data,設置屬性為Verticalscroll和Wantreturn。

兩個按鈕對應的讀寫函數分別如下

voidCFileTxtDlg::OnRead()

{

//TODO:

CFileDialogfDlg(TRUE);

fDlg.m_ofn.lpstrFilter="TextFiles(*.txt)*.txt";

if(fDlg.DoModal()==IDOK)

{

CStdioFilestdFile;

stdFile.Open(fDlg.GetPathName(),CFile::modeRead|CFile::typeBinary);

DWORDfileLen=stdFile.GetLength();

char*pBuf=newchar[fileLen+1];

pBuf[fileLen]=0;

stdFile.Read(pBuf,fileLen);

UpdateData();

m_Data=pBuf;

UpdateData(FALSE);

deletepBuf;

stdFile.Close();

}

}

voidCFileTxtDlg::OnWrite()

{

//TODO:

UpdateData();

CFileDialogfDlg(FALSE);

fDlg.m_ofn.lpstrFilter="TextFiles(*.txt)*.txt";

fDlg.m_ofn.lpstrDefExt="txt";

if(IDOK==fDlg.DoModal())

{

CStdioFilestdFile;

stdFile.Open(fDlg.GetPathName(),CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);

stdFile.WriteString(m_Data);

stdFile.Close();

}

}

如要源代碼發消息

閱讀全文

與mfctxt執行了但不寫文件相關的資料

熱點內容
企業微信素材庫文件下載鏈接 瀏覽:582
pdf文件怎麼取消標黃 瀏覽:781
打電話時不能使用網路是什麼原因 瀏覽:919
ps怎麼將文件合並 瀏覽:747
java的日期格式化 瀏覽:981
電腦應用程序怎麼關 瀏覽:986
微信上鏈接在哪個文件夾 瀏覽:691
歐姆龍安裝打開找不到密鑰文件 瀏覽:302
蘋果基本表情 瀏覽:128
我的世界教育版編程在哪裡 瀏覽:842
pong文件夾找不到 瀏覽:759
69版本黑切 瀏覽:997
杭州道富java 瀏覽:635
知道qq號查微博賬號和密碼 瀏覽:294
紅手指自帶哪些app 瀏覽:103
手機用公司網路會被監控哪些 瀏覽:409
什麼叫py編程 瀏覽:370
微信紅包尾數作弊器ios 瀏覽:280
ipad備份文件夾 瀏覽:555
vivo手機qq下載的文件在哪裡 瀏覽:303

友情鏈接