您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
(1)读文件
VOID CScale3DCControl::ReadLauFile(CString strFileName,CRichEditCtrl & richEdit) { CString strFilePath = GetApplicationPath() + strFileName; CFile file(strFilePath, CFile::modeRead); char * pBuf; DWORD dwFileLen; //定义存储文件长度的变量 dwFileLen = file.GetLength(); pBuf = new char[dwFileLen + 1]; pBuf[dwFileLen] = 0; //把最后一位一0结尾 表示文件结束 file.Read(pBuf, dwFileLen); USES_CONVERSION; richEdit.SetWindowText(A2W(pBuf)); GetKeyWordFromText(A2W(pBuf)); file.Close(); }
(2)写文件
VOID CScale3DCControl::SaveLuaFile(CRichEditCtrl & richEdit, CString strFileName) { CString strPath = GetApplicationPath() + _T("lua\\") + strFileName; CFile file(strPath,CFile::modeCreate | CFile::modeWrite); CString strTemp; richEdit.GetWindowText(strTemp); USES_CONVERSION; file.Write(W2A(strTemp), strlen(W2A(strTemp))); file.Close(); }
(3)搜索文件夹下的所有文件名
void CScale3DCControl::GetFileFromDirectory(CString csDirPath, CListBox & list) //csDirPath为文件夹名字,把该文件夹底下的jpg文 //件的名字存储到容器 m_FileList中,如果不分类型 //则把csDirPath+="\\*.jpg";改为csDirPat+="\*." { m_FileList.clear(); list.ResetContent(); csDirPath = GetApplicationPath()+csDirPath+ _T("\\*.lua"); HANDLE file; WIN32_FIND_DATA fileData; file = FindFirstFile(csDirPath.GetBuffer(), &fileData); if (file != INVALID_HANDLE_VALUE) { m_FileList.push_back(fileData.cFileName); list.AddString(fileData.cFileName); bool bState = false; bState = FindNextFile(file, &fileData); while (bState) { m_FileList.push_back(fileData.cFileName); list.AddString(fileData.cFileName); bState = FindNextFile(file, &fileData); } } else { ;// AfxMessageBox("文件夹中没有shp文件!"); } } CString CScale3DCControl::GetApplicationPath() { WCHAR buff[255] = { 0 }; ::GetModuleFileName(0, buff, 255); CString strAppFullName; strAppFullName.Format(_T("%s"), buff); CString strAppPath = _T(""); strAppPath = strAppFullName.Left(strAppFullName.ReverseFind('\\') + 1); return strAppPath; }
c语言读写文件,如下:
VOID CScale3DCFileData::GetCharFromFile(TCHAR szChina[]) { if (!m_strFilePath)return; errno_t err; FILE *fd; err = _wfopen_s(&fd, m_strFilePath, _T("r")); INT i = 0; if (err == 0) { char buff[100] = { 0 }; while (fgets(buff, 100, fd) != NULL) { USES_CONVERSION; CString strBuff = A2W(buff); INT nLength = strBuff.GetLength(); for (INT j = 0; j < nLength - 1; j++) { if (i >= 34) { m_sFlag = strBuff[j]; break; } szChina[i++] = strBuff[j]; } } } fclose(fd); } VOID CScale3DCFileData::SaveCharToFile(TCHAR* szChina) { USES_CONVERSION; FILE * fd; errno_t err; err = _wfopen_s(&fd, m_strFilePath, _T("w") ); if (err == 0) { char * p = W2A(szChina); fputs(p, fd); } fclose(fd); }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。