日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

INI文件读写--VC6.0

發布時間:2023/12/9 c/c++ 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 INI文件读写--VC6.0 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

新建一個dialog based MFC Windows Application,命名為:d, 界面為:

為按鈕Read和Write添加單擊事件,并自定義一個函數GetIniFileName()用來取得ini文件的路徑,主要函數代碼如下: // read data from config file void CDDlg::OnBtnRead() // 從INI文件中讀取指定的信息,更新到編輯框中 {char userName[64], password[64];int score_Chinese, score_Mathematics;CString sIniFile = GetIniFileName(); // 取得配置文件全路徑memset(userName, 0, sizeof(userName)); // 填充字符串數組memset(password, 0, sizeof(password));// read values from the specified config fileGetPrivateProfileString(SECTION_USERINFO, "UserName", "", userName, 63, sIniFile); // read a string from the specified config fileGetPrivateProfileString(SECTION_USERINFO, "Password", "", password, 63, sIniFile);score_Chinese = GetPrivateProfileInt(SECTION_SCORE, "Chinese", 0, sIniFile); // read an integer from the specified config filescore_Mathematics = GetPrivateProfileInt(SECTION_SCORE, "Mathematics", 0, sIniFile);// Update values to the controlsCString tempValue;((CEdit*) GetDlgItem(IDC_EDIT_USERNAME))->SetWindowText(userName);((CEdit*) GetDlgItem(IDC_EDIT_PASSWORD))->SetWindowText(password);tempValue.Format("%d", score_Chinese);((CEdit*) GetDlgItem(IDC_EDIT_CHINESE))->SetWindowText(tempValue); // 10:代表十進制tempValue.Format("%d", score_Mathematics);((CEdit*) GetDlgItem(IDC_EDIT_MATHEMATICS))->SetWindowText(tempValue);MessageBox("Read data from config file successfully!", "Information", MB_OK | MB_ICONINFORMATION); // ((CStatic *) GetDlgItem(IDC_TXT_MESSAGE))->SetWindowText("Read data from config file successfully!"); }// store data to config file void CDDlg::OnBtnwrite() {// TODO: Add your control notification handler code herechar userName[64], password[64], sValue[20];int score_Chinese, score_Mathematics;((CEdit *) GetDlgItem(IDC_EDIT_USERNAME))->GetWindowText(userName, 63);((CEdit *) GetDlgItem(IDC_EDIT_PASSWORD))->GetWindowText(password, 63);((CEdit *) GetDlgItem(IDC_EDIT_CHINESE))->GetWindowText(sValue, 19);score_Chinese = atoi(sValue);((CEdit *) GetDlgItem(IDC_EDIT_MATHEMATICS))->GetWindowText(sValue, 19);score_Mathematics = atoi(sValue);// Write data to the config fileCString sIniFile = GetIniFileName();CString tempValue;WritePrivateProfileString(SECTION_USERINFO, "UserName", userName, sIniFile);WritePrivateProfileString(SECTION_USERINFO, "Password", password, sIniFile);tempValue.Format("%d", score_Chinese);WritePrivateProfileString(SECTION_SCORE, "Chinese", tempValue, sIniFile);tempValue.Format("%d", score_Mathematics);WritePrivateProfileString(SECTION_SCORE, "Mathematics", tempValue, sIniFile);MessageBox("Write data to config file successfully!", "Information", MB_OK | MB_ICONEXCLAMATION); // ((CStatic *) GetDlgItem(IDC_TXT_MESSAGE))->SetWindowText("Write data to config file successfully!"); }// get the file path of config file CString CDDlg::GetIniFileName() const {CString Result, sPath;Result = _T("");char sFileName[256];GetModuleFileName(AfxGetInstanceHandle(), sFileName, 255); // 取得當前可執行文件的路徑,保存在sFileName中sPath = sFileName;int index = sPath.ReverseFind('\\'); // 逆向查找指定字符sPath = sPath.Left(index);Result = sPath + "\\Config.ini";return Result; }
其中,ini文件中的內容為: [UserInfo]
UserName=tian
Password=123456zhou [Score]
Chinese=55
Mathematics=66
源碼下載:http://d.download.csdn.net/down/2735337/JoeBlackzqq

總結

以上是生活随笔為你收集整理的INI文件读写--VC6.0的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。