算法测试平台搭建常用代码备份
来源:互联网 发布:网络三巨头是什么意思 编辑:程序博客网 时间:2024/05/20 23:05
最近要在windows平台下搭建一个简单的算法测试平台进行算法的测试(又要做windows下算法的开发~)
故而把一些常用的MFC代码的的代码总结如下
- 选择路径对话框
void CMuraDetectDlg::OnMenuChoosePath(){ // TODO: 在此添加命令处理程序代码 wchar_t szPath[MAX_PATH] = {0}; BROWSEINFO bi; bi.hwndOwner = m_hWnd; bi.pidlRoot = NULL; bi.lpszTitle = _T("请选择需要打包的目录:"); bi.ulFlags = 0; bi.lpfn = NULL; bi.lParam = 0; bi.iImage = 0; bi.pszDisplayName = szPath; //弹出选择目录对话框 LPITEMIDLIST lp = SHBrowseForFolder(&bi); if (lp && SHGetPathFromIDList(lp, szPath)) { CString str; str.Format(_T("选择的目录为 %s"), szPath); AfxMessageBox(str); } else { AfxMessageBox(_T("无效的目录,请重新选择")); } m_file_path = m_util.UnicodeToANSI(szPath);}
- MFC下各种编码格式的转换
// ANSI to Unicodewstring CUtil::ANSIToUnicode(const string& str){ int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen + 1]; memset(pUnicode, 0, (unicodeLen + 1)*sizeof(wchar_t)); ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen); wstring rt; rt = (wchar_t*)pUnicode; delete pUnicode; return rt;}//Unicode to ANSIstring CUtil::UnicodeToANSI(const wstring& str){ char* pElementText; int iTextLen; // wide char to multi char iTextLen = WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL); pElementText = new char[iTextLen + 1]; memset((void*)pElementText, 0, sizeof(char)* (iTextLen + 1)); ::WideCharToMultiByte(CP_ACP, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL); string strText; strText = pElementText; delete[] pElementText; return strText;}// UTF - 8 to Unicodewstring CUtil::UTF8ToUnicode(const string& str){ int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen + 1]; memset(pUnicode, 0, (unicodeLen + 1)*sizeof(wchar_t)); ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen); wstring rt; rt = (wchar_t*)pUnicode; delete pUnicode; return rt;}// Unicode to UTF - 8string CUtil::UnicodeToUTF8(const wstring& str){ char* pElementText; int iTextLen; // wide char to multi char iTextLen = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL); pElementText = new char[iTextLen + 1]; memset((void*)pElementText, 0, sizeof(char)* (iTextLen + 1)); ::WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL); string strText; strText = pElementText; delete[] pElementText; return strText;}
- 获取指定文件夹下所有的指定格式的文件
这里用到了boost,自从做服务器开发用到了boost,就离不开了,什么功能都想直接用boost,果然有毒呀!!
int CUtil::get_path_allfiles(const std::string& dir, const std::string fmt, bool mult_layer, std::vector<std::string>& filenames){ filesystem::path path(dir); if (!filesystem::exists(path)) { return -1; } filesystem::directory_iterator end_iter; for (filesystem::directory_iterator iter(path); iter != end_iter; ++iter) { if (filesystem::is_regular_file(iter->status())) { string tmp_name = iter->path().string(); if (tmp_name.size() < 4) { continue; } tmp_name = tmp_name.substr(tmp_name.size() - 4, 4); if (tmp_name.compare(fmt) == 0) { filenames.push_back(iter->path().string()); } } if (filesystem::is_directory(iter->status())) { if (mult_layer) { get_path_allfiles(iter->path().string(), fmt, mult_layer, filenames); } } } return (int)filenames.size();}
- 4.
0 0
- 算法测试平台搭建常用代码备份
- 算法常用代码代码备份
- 常用排序算法代码测试
- 如何 搭建 RMAN 备份平台
- 如何 搭建 RMAN 备份平台
- 如何 搭建 RMAN 备份平台
- 如何 搭建 RMAN 备份平台
- 如何 搭建 RMAN 备份平台
- 如何 搭建 RMAN 备份平台
- JAVASCRIPT常用代码备份
- 常用分页代码备份
- android 常用代码备份
- 状态栏常用代码备份
- 常用代码备份--多线程
- 室内清扫机器人环境搭建与算法测试简易代码
- 常用代码备份--资源切换
- 常用代码备份--字符串处理
- 跨平台Socket 代码测试
- mongodb分片部署和管理
- 494 - Kindergarten Counting Game
- 手动创建docker垮主机网络环境
- FFMPEG Installation compile build
- WPF中非UI线程修改UI元素
- 算法测试平台搭建常用代码备份
- 传输块(Transport Block)大小的计算
- wordpress搭建
- 个人主页
- TCP三次握手/四次挥手详解
- 连续子数组的最大和
- iOS 基础篇14- KVO的使用
- 2016 JAVA与Android面试题整理
- “fatal error C1083 ”无法打开包括文件