算法测试平台搭建常用代码备份
2016-06-22 20:37
381 查看
最近要在windows平台下搭建一个简单的算法测试平台进行算法的测试(又要做windows下算法的开发~)
故而把一些常用的MFC代码的的代码总结如下
选择路径对话框
MFC下各种编码格式的转换
获取指定文件夹下所有的指定格式的文件
这里用到了boost,自从做服务器开发用到了boost,就离不开了,什么功能都想直接用boost,果然有毒呀!!
4.
故而把一些常用的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 Unicode wstring 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 ANSI string 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 Unicode wstring 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 - 8 string 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.
相关文章推荐
- java 单例模式的7种实现方法
- 设计模式 - 代理模式
- 2.5、Hello World入门
- 【Leetcode】:28. Implement strStr()问题 in JAVA
- 【SpringMVC学习06】SpringMVC中的数据校验
- java动态代理Proxy
- 双向循环链表
- ThinkPHP框架表单验证
- 射击类飞机游戏
- 解决eclipse中Adb connection Error:远程主机强迫关闭了一个现有的连接 的问题
- java与C++的区别
- 求二叉树的宽度C语言版
- C++ 虚继承和虚函数同时存在的对象模型
- 分享代码
- C++帮助手册man的安装和使用方法
- GO语言学习:JSON处理
- spring全注解项目
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- C++05、初识类和对象
- Java线程池