https://ciang.top/ https://ciang.top/
首页
  • 首页
  • python
  • 工具经验
  • 教程
  • c++
  • mysql
  • 登录
搜索历史 清空
写文章

登录

账号密码登录
扫码登录
扫码登录
请使用手机扫码登录
注册登录即表示同意用户协议和隐私政策
编程
java c/c++ mysql python excel html/css/js 工具经验
思路/心得
传奇私服-V8M2引擎学习笔记
教程
翻译
游戏
推荐 最新
C++将不同编码的字符串写入文件
benojan 2025-4-5

C++将不同编码的字符串写入文件

u8string 以文本模式进行保存 #include <fstream> #include <iostream> int main() { std::u8string u8str = u8"你好𣍐,世界!This is a UTF-8 string."; const char* filename = "output_u8.txt"; std::ofstream outfile(filename); // 默认以文本模式打开 if (outfile.is_open()) { outfile << reinterpret_cast<const char*>(u8str.c_str()); outfile.close(); std::cout << "std::u8string 已写入文件 " << filename << " (UTF-8)." << std::endl; } else { std::cerr << "无法打开文件 " << filename << std::endl; return 1; } return 0; } 以二进制模式进行保存 #include <fstream> #include <iostream> int main() { std::u8string u8str = u8"你好𣍐,世界!This is a UTF-8 string."; const char* filename = "output_u8.txt"; std::ofstream outfile(filename, std::ios::binary); // 以二进制模式打开 if (outfile.is_open()) { outfile.write(reinterpret_cast<const char*>(u8str.c_str()), u8str.length() * sizeof(char8_t)); outfile.close(); std::cout << "std::u8string 已写入文件 " << filename << " (UTF-8)." << std::endl; } else { std::cerr << "无法打开文件 " << filename << std::endl; return 1; } return 0; } u16string 以UTF-16 Little-Endian进行保存 #include <fstream> #include <iostream> int main() { std::u16string u16str = u"你好𣍐,世界!This is a test."; const char* filename = "output_u16le.txt"; std::ofstream outfile(filename, std::ios::binary); if (outfile.is_open()) { // 写入 UTF-16 Little-Endian BOM unsigned char bom[] = { 0xFF, 0xFE }; outfile.write(reinterpret_cast<const char*>(bom), sizeof(bom)); // 将 std::u16string 的数据作为原始字节写入 outfile.write(reinterpret_cast<const char*>(u16str.c_str()), u16str.length() * sizeof(char16_t)); outfile.close(); std::cout << "std::u16string 已写入文件 " << filename << " (UTF-16 Little-Endian)." << std::endl; } else { std::cerr << "无法打开文件 " << filename << std::endl; return 1; } return 0; } 以UTF-16 Big-Endian进行保存 #include <fstream> #include <iostream> #include <vector> int main() { std::u16string u16str = u"你好𣍐,世界!This is a test."; const char* filename = "output_u16be.txt"; std::ofstream outfile(filename, std::ios::binary); if (outfile.is_open()) { // 写入 UTF-16 Big-Endian BOM unsigned char bom[] = { 0xFE, 0xFF }; outfile.write(reinterpret_cast<const char*>(bom), sizeof(bom)); // 将 std::u16string 的数据作为原始字节写入 (需要字节序转换) std::vector<char> buffer(u16str.length() * sizeof(char16_t)); std::memcpy(buffer.data(), u16str.c_str(), buffer.size()); // 交换每两个字节的顺序以实现 Big-Endian for (size_t i = 0; i < buffer.size(); i += 2) { std::swap(buffer[i], buffer[i + 1]); } outfile.write(buffer.data(), buffer.size()); outfile.close(); std::cout << "std::u16string 已写入文件 " << filename << " (UTF-16 Big-Endian)." << std::endl; } else { std::cerr << "无法打开文件 " << filename << std::endl; return 1; } return 0; }

430 27 0
编码
高DPI适配
benojan 2024-8-8

高DPI适配

496 27 0
Windows窗口程序
高DPI适配
C++ DLL的制作与使用
benojan 2024-4-11

C++ DLL的制作与使用

制作DLL // calc.h #ifdef EXPORT_DLL #define CALC_API __declspec(dllexport) #else #define CALC_API __declspec(dllimport) #endif extern "C" { CALC_API int 加(int a, int b); CALC_API int 减(int a, int b); CALC_API int 乘(int a, int b); CALC_API double 除(double a, double b); } // calc.cpp #define EXPORT_DLL #include "calc.h" extern "C" { CALC_API int 加(int a, int b) { return a + b; } CALC_API int 减(int a, int b) { return a - b; } CALC_API int 乘(int a, int b) { return a * b; } CALC_API double 除(double a, double b) { return a / b; } } // CMakeLists.txt cmake_minimum_required(VERSION 3.10) project(calc) set(CMAKE_CXX_STANDARD 11) if(MSVC) add_compile_options("/source-charset:utf-8") endif() include_directories(./include) if(MSVC) add_compile_options("/source-charset:utf-8") endif() file(GLOB SOURCES "./src/*.cpp") add_library(${PROJECT_NAME} SHARED ${SOURCES}) 使用DLL // useCalc.cpp #include <iostream> #include "calc.h" using namespace std; int main() { cout << 加(3, 4) << endl; } // CMakeLists.txt cmake_minimum_required(VERSION 3.10) project(useCalc) set(CMAKE_CXX_STANDARD 11) if(MSVC) add_compile_options("/source-charset:utf-8") endif() file(GLOB SOURCES "src/*.cpp") include_directories(include) add_executable(${PROJECT_NAME} ${SOURCES}) target_link_libraries(${PROJECT_NAME} calc)

589 27 0
c++dllcmake
Accelerators and WTL Dialogs
benojan 2024-3-9

Accelerators and WTL Dialogs

Author: Rory Buchanan Date: 2006 Introduction I searched and searched the CodeProject but never found an example on using accelerators and WTL dialogs. I have used accelerators in MFC dialogs extensively, but couldn't figure out how to add this functionality to WTL dialogs. Like a lot of things, it is very easy to do once you have figured it out. Well, here goes.... Using the code Declare a handle to the accelerator, and add the CMessageFilter if it has not been done already. #pragma once class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>, public CMessageFilter, public CIdleHandler { private: HACCEL m_haccelerator; //....... }; Then in your OnInitDialog, assign the m_haccelerator variable to the accelerator resource, which in this example is IDR_MAINFRAME. LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { // ....... //Bind keys... m_haccelerator = AtlLoadAccelerators(IDR_MAINFRAME); // register object for message filtering and idle updates CMessageLoop* pLoop = _Module.GetMessageLoop(); ATLASSERT(pLoop != NULL); pLoop->AddMessageFilter(this); pLoop->AddIdleHandler(this); //............... return TRUE; } Then we need to overload the PreTranslateMessage function... BOOL CMainDlg::PreTranslateMessage(MSG* pMsg) { if(m_haccelerator != NULL) { if(::TranslateAccelerator(m_hWnd, m_haccelerator, pMsg)) return TRUE; } return CWindow::IsDialogMessage(pMsg); } Also, in you constructor, initialize the handle to the accelerator. CMainDlg::CMainDlg() { //.................. m_haccelerator = NULL; //.................. } If the dialog wasn't made to be modeless, it needs to be for the PreTranslateMessage to work. This is easily done by... int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) { _Module.Init(NULL, hInstance); CMessageLoop myMessageLoop; _Module.AddMessageLoop(&myMessageLoop); CMainDlg dlgMain; dlgMain.Create(NULL); dlgMain.ShowWindow(nCmdShow); int retValue = myMessageLoop.Run(); _Module.RemoveMessageLoop(); _Module.Term(); return retValue; } And make sure you include atlmisc.h.

780 27 0
WTLAcceleratorsModeless
MFC 控件使用之ListCtrl之一
benojan 2024-3-8

MFC 控件使用之ListCtrl之一

作者:lixiaosan 时间:04/06/2006 以下未经说明,listctrl默认view 风格为report 相关类及处理函数 MFC:CListCtrl类 SDK:以 “ListView_”开头的一些宏。如 ListView_InsertColumn 1. CListCtrl 风格 LVS_ICON: 为每个item显示大图标 LVS_SMALLICON: 为每个item显示小图标 LVS_LIST: 显示一列带有小图标的item LVS_REPORT: 显示item详细资料 直观的理解:windows资源管理器,“查看”标签下的“大图标,小图标,列表,详细资料” 2. 设置 listctrl 风格及扩展风格 LONG lStyle; lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE); //获取当前窗口style lStyle &= ~LVS_TYPEMASK; //清除显示方式位 lStyle |= LVS_REPORT; //设置style SetWindowLong(m_list.m_hWnd, GWL_STYLE, lStyle); //设置style DWORD dwStyle = m_list.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT; //选中某行使整行高亮(只适用与report风格的listctrl) dwStyle |= LVS_EX_GRIDLINES; //网格线(只适用与report风格的listctrl) dwStyle |= LVS_EX_CHECKBOXES; //item前生成checkbox控件 m_list.SetExtendedStyle(dwStyle); //设置扩展风格 注:listview的style请查阅msdn http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceshellui5/html/wce50lrflistviewstyles.asp 3. 插入数据 m_list.InsertColumn( 0, "ID", LVCFMT_LEFT, 40 ); //插入列 m_list.InsertColumn( 1, "NAME", LVCFMT_LEFT, 50 ); int nRow = m_list.InsertItem(0, “11”); //插入行 m_list.SetItemText(nRow, 1, “jacky”); //设置数据 4. 一直选中 item 选中属性中的 始终显示选定内容, 或者在上面第2点中设置 LVS_SHOWSELALWAYS 5. 选中和取消选中一行 int nIndex = 0; // 选中 m_list.SetItemState(nIndex, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); // 取消选中 m_list.SetItemState(nIndex, 0, LVIS_SELECTED|LVIS_FOCUSED); 6. 得到listctrl中所有行的checkbox的状态 m_list.SetExtendedStyle(LVS_EX_CHECKBOXES); CString str; for(int i=0; i<m_list.GetItemCount(); i++) { if( m_list.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED || m_list.GetCheck(i)) { str.Format(_T("第%d行的checkbox为选中状态"), i); AfxMessageBox(str); } } 7. 得到listctrl中所有选中行的序号 // 方法一: CString str; for(int i=0; i<m_list.GetItemCount(); i++) { if( m_list.GetItemState(i, LVIS_SELECTED) == LVIS_SELECTED ) { str.Format(_T("选中了第%d行"), i); AfxMessageBox(str); } } // 方法二: POSITION pos = m_list.GetFirstSelectedItemPosition(); if (pos == NULL) TRACE0("No items were selected!\n"); else { while (pos) { int nItem = m_list.GetNextSelectedItem(pos); TRACE1("Item %d was selected!\n", nItem); // you could do your own processing on nItem here } } 8. 得到item的信息 TCHAR szBuf[1024]; LVITEM lvi; lvi.iItem = nItemIndex; lvi.iSubItem = 0; lvi.mask = LVIF_TEXT; lvi.pszText = szBuf; lvi.cchTextMax = 1024; m_list.GetItem(&lvi); 关于得到设置item的状态,还可以参考msdn文章 Q173242: Use Masks to Set/Get Item States in CListCtrl http://support.microsoft.com/kb/173242/en-us 8.1 得到选中的行的每一项的信息 // 得到具体的某一项: CString str; int nId; // 首先得到点击的位置 POSITION pos = m_listcontrol.GetFirstSelectedItemPosition(); if(pos == NULL) { MessageBox("请至少选择一项","娃子理财", MB_ICONEXCLAMATION); return; } // 得到行号,通过POSITION转化 nId = (int) m_listcontrol.GetNextSelectedItem(pos); //得到列中的内容(0表示第一列,同理1,2,3...表示第二,三,四...列) str = m_listcontrol.GetItemText(nId, 0); str = m_listcontrol.GetItemText(nId, 1); 9. 得到listctrl的所有列的header字符串内容 LVCOLUMN lvcol; char str[256]; int nColNum; CString strColumnName[4];//假如有4列 nColNum = 0; lvcol.mask = LVCF_TEXT; lvcol.pszText = str; lvcol.cchTextMax = 256; while(m_list.GetColumn(nColNum, &lvcol)) { strColumnName[nColNum] = lvcol.pszText; nColNum++; } 10. 使listctrl中一项可见,即滚动滚动条 m_list.EnsureVisible(i, FALSE); 11. 得到listctrl列数 int nHeadNum = m_list.GetHeaderCtrl()->GetItemCount(); 12. 删除所有列 // 方法一: while ( m_list.DeleteColumn (0)) // 因为你删除了第一列后,后面的列会依次向上移动。 // 方法二: int nColumns = 4; for (int i=nColumns-1; i>=0; i--) m_list.DeleteColumn (i); 13. 得到单击的listctrl的行列号 // 添加listctrl控件的NM_CLICK消息相应函数 void CTest6Dlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) { // 方法一: DWORD dwPos = GetMessagePos(); CPoint point( LOWORD(dwPos), HIWORD(dwPos) ); m_list.ScreenToClient(&point); LVHITTESTINFO lvinfo; lvinfo.pt = point; lvinfo.flags = LVHT_ABOVE; int nItem = m_list.SubItemHitTest(&lvinfo); if(nItem != -1) { CString strtemp; strtemp.Format("单击的是第%d行第%d列", lvinfo.iItem, lvinfo.iSubItem); AfxMessageBox(strtemp); } // 方法二: NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; if(pNMListView->iItem != -1) { CString strtemp; strtemp.Format("单击的是第%d行第%d列", pNMListView->iItem, pNMListView->iSubItem); AfxMessageBox(strtemp); } *pResult = 0; } 14. 判断是否点击在listctrl的checkbox上 // 添加listctrl控件的NM_CLICK消息相应函数 void CTest6Dlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) { DWORD dwPos = GetMessagePos(); CPoint point( LOWORD(dwPos), HIWORD(dwPos) ); m_list.ScreenToClient(&point); LVHITTESTINFO lvinfo; lvinfo.pt = point; lvinfo.flags = LVHT_ABOVE; UINT nFlag; int nItem = m_list.HitTest(point, &nFlag); //判断是否点在checkbox上 if(nFlag == LVHT_ONITEMSTATEICON) { AfxMessageBox("点在listctrl的checkbox上"); } *pResult = 0; } 右键点击listctrl的item弹出菜单 // 添加listctrl控件的NM_RCLICK消息相应函数 void CTest6Dlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; if(pNMListView->iItem != -1) { DWORD dwPos = GetMessagePos(); CPoint point( LOWORD(dwPos), HIWORD(dwPos) ); CMenu menu; VERIFY( menu.LoadMenu( IDR_MENU1 ) ); CMenu* popup = menu.GetSubMenu(0); ASSERT( popup != NULL ); popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this ); } *pResult = 0; } 16. item切换焦点时(包括用键盘和鼠标切换item时),状态的一些变化顺序 // 添加listctrl控件的LVN_ITEMCHANGED消息相应函数 void CTest6Dlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // TODO: Add your control notification handler code here CString sTemp; if((pNMListView->uOldState & LVIS_FOCUSED) == LVIS_FOCUSED && (pNMListView->uNewState & LVIS_FOCUSED) == 0) { sTemp.Format("%d losted focus",pNMListView->iItem); } else if((pNMListView->uOldState & LVIS_FOCUSED) == 0 && (pNMListView->uNewState & LVIS_FOCUSED) == LVIS_FOCUSED) { sTemp.Format("%d got focus",pNMListView->iItem); } if((pNMListView->uOldState & LVIS_SELECTED) == LVIS_SELECTED && (pNMListView->uNewState & LVIS_SELECTED) == 0) { sTemp.Format("%d losted selected",pNMListView->iItem); } else if((pNMListView->uOldState & LVIS_SELECTED) == 0 && (pNMListView->uNewState & LVIS_SELECTED) == LVIS_SELECTED) { sTemp.Format("%d got selected",pNMListView->iItem); } *pResult = 0; } 17. 得到另一个进程里的listctrl控件的item内容 http://www.codeproject.com/threads/int64_memsteal.asp 18. 选中listview中的item Q131284: How To Select a Listview Item Programmatically http://support.microsoft.com/kb/131284/en-us 19. 如何在CListView中使用CListCtrl的派生类 http://www.codeguru.com/cpp/controls/listview/introduction/article.php/c919/ 20. listctrl的subitem添加图标 m_list.SetExtendedStyle(LVS_EX_SUBITEMIMAGES); m_list.SetItem(..); // 具体参数请参考msdn 21. 在CListCtrl显示文件,并根据文件类型来显示图标 // 网上找到的代码,share BOOL CTest6Dlg::OnInitDialog() { CDialog::OnInitDialog(); HIMAGELIST himlSmall; HIMAGELIST himlLarge; SHFILEINFO sfi; char cSysDir[MAX_PATH]; CString strBuf; memset(cSysDir, 0, MAX_PATH); GetWindowsDirectory(cSysDir, MAX_PATH); strBuf = cSysDir; sprintf(cSysDir, "%s", strBuf.Left(strBuf.Find("\\")+1)); himlSmall = (HIMAGELIST)SHGetFileInfo ((LPCSTR)cSysDir, 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON ); himlLarge = (HIMAGELIST)SHGetFileInfo((LPCSTR)cSysDir, 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); if (himlSmall && himlLarge) { ::SendMessage(m_list.m_hWnd, LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)himlSmall); ::SendMessage(m_list.m_hWnd, LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)himlLarge); } return TRUE; // return TRUE unless you set the focus to a control } void CTest6Dlg::AddFiles(LPCTSTR lpszFileName, BOOL bAddToDocument) { int nIcon = GetIconIndex(lpszFileName, FALSE, FALSE); CString strSize; CFileFind filefind; // get file size if (filefind.FindFile(lpszFileName)) { filefind.FindNextFile(); strSize.Format("%d", filefind.GetLength()); } else strSize = "0"; // split path and filename CString strFileName = lpszFileName; CString strPath; int nPos = strFileName.ReverseFind('\\'); if (nPos != -1) { strPath = strFileName.Left(nPos); strFileName = strFileName.Mid(nPos + 1); } // insert to list int nItem = m_list.GetItemCount(); m_list.InsertItem(nItem, strFileName, nIcon); m_list.SetItemText(nItem, 1, strSize); m_list.SetItemText(nItem, 2, strFileName.Right(3)); m_list.SetItemText(nItem, 3, strPath); } int CTest6Dlg::GetIconIndex(LPCTSTR lpszPath, BOOL bIsDir, BOOL bSelected) { SHFILEINFO sfi; memset(&sfi, 0, sizeof(sfi)); if (bIsDir) { SHGetFileInfo(lpszPath, FILE_ATTRIBUTE_DIRECTORY, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES |(bSelected ? SHGFI_OPENICON : 0)); return sfi.iIcon; } else { SHGetFileInfo (lpszPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES | (bSelected ? SHGFI_OPENICON : 0)); return sfi.iIcon; } return -1; } 22. listctrl内容进行大数据量更新时,避免闪烁 m_list.SetRedraw(FALSE); //更新内容 m_list.SetRedraw(TRUE); m_list.Invalidate(); m_list.UpdateWindow(); 或者参考 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.setredraw.asp 23. listctrl排序 Q250614:How To Sort Items in a CListCtrl in Report View http://support.microsoft.com/kb/250614/en-us 24. 在listctrl中选中某个item时动态改变其icon或bitmap Q141834: How to change the icon or the bitmap of a CListCtrl item in Visual C++ http://support.microsoft.com/kb/141834/en-us 25. 在添加item后,再InsertColumn()后导致整列数据移动的问题 Q151897: CListCtrl::InsertColumn() Causes Column Data to Shift http://support.microsoft.com/kb/151897/en-us 26. 关于listctrl第一列始终居左的问题 解决办法:把第一列当一个虚列,从第二列开始插入列及数据,最后删除第一列。 具体解释参阅 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/structures/lvcolumn.asp 27. 锁定column header的拖动 http://msdn.microsoft.com/msdnmag/issues/03/06/CQA/ 28. 如何隐藏clistctrl的列 把需隐藏的列的宽度设为0,然后检测当该列为隐藏列时,用上面第27点的锁定column 的拖动来实现 29. listctrl进行大数据量操作时,使用virtual list http://www.microsoft.com/msj/archive/S2061.aspx http://www.codeguru.com/cpp/controls/listview/advanced/article.php/c4151/ http://www.codeproject.com/listctrl/virtuallist.asp 30. 关于item只能显示259个字符的问题 解决办法:需要在item上放一个edit。 31. 响应在listctrl的column header上的鼠标右键单击 Q125694: How To Find Out Which Listview Column Was Right-Clicked http://support.microsoft.com/kb/125694/en-us 32. 类似于windows资源管理器的listview Q234310: How to implement a ListView control that is similar to Windows Explorer by using DirLV.exe http://support.microsoft.com/kb/234310/en-us 33. 在ListCtrl中OnTimer只响应两次的问题 Q200054:PRB: OnTimer() Is Not Called Repeatedly for a List Control http://support.microsoft.com/kb/200054/en-us 34. 以下为一些为实现各种自定义功能的listctrl派生类 拖放 http://www.codeproject.com/listctrl/dragtest.asp 在CListCtrl和CTreeCtrl间拖放 http://support.microsoft.com/kb/148738/en-us 多功能listctrl 支持subitem可编辑,图标,radiobutton,checkbox,字符串改变颜色的类 http://www.codeproject.com/listctrl/quicklist.asp 支持排序,subitem可编辑,subitem图标,subitem改变颜色的类 http://www.codeproject.com/listctrl/ReportControl.asp subitem中显示超链接 http://www.codeproject.com/listctrl/CListCtrlLink.asp subitem的tooltip提示 http://www.codeproject.com/listctrl/ctooltiplistctrl.asp subitem中显示进度条 http://www.codeproject.com/listctrl/ProgressListControl.asp http://www.codeproject.com/listctrl/napster.asp http://www.codeguru.com/Cpp/controls/listview/article.php/c4187/ 动态改变subitem的颜色和背景色 http://www.codeproject.com/listctrl/highlightlistctrl.asp http://www.codeguru.com/Cpp/controls/listbox/colorlistboxes/article.php/c4757/ 类vb属性对话框 http://www.codeproject.com/listctrl/propertylistctrl.asp http://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c995/ http://www.codeguru.com/Cpp/controls/listview/propertylists/article.php/c1041/ 选中subitem(只高亮选中的item) http://www.codeproject.com/listctrl/SubItemSel.asp http://www.codeproject.com/listctrl/ListSubItSel.asp 改变行高 http://www.codeproject.com/listctrl/changerowheight.asp 改变行颜色 http://www.codeproject.com/listctrl/coloredlistctrl.asp 可编辑subitem的listctrl http://www.codeproject.com/listctrl/nirs2000.asp http://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp subitem可编辑,插入combobox,改变行颜色,subitem的tooltip提示 http://www.codeproject.com/listctrl/reusablelistcontrol.asp header 中允许多行字符串 http://www.codeproject.com/listctrl/headerctrlex.asp 插入combobox http://www.codeguru.com/Cpp/controls/listview/editingitemsandsubitem/article.php/c979/ 添加背景图片 http://www.codeguru.com/Cpp/controls/listview/backgroundcolorandimage/article.php/c4173/ http://www.codeguru.com/Cpp/controls/listview/backgroundcolorandimage/article.php/c983/ http://www.vchelp.net/vchelp/archive.asp?type_id=9&class_id=1&cata_id=1&article_id=1088&search_term= 自适应宽度的listctrl http://www.codeproject.com/useritems/AutosizeListCtrl.asp 改变ListCtrl高亮时的颜色(默认为蓝色) 处理 NM_CUSTOMDRAW http://www.codeproject.com/listctrl/lvcustomdraw.asp 改变header颜色 http://www.pocketpcdn.com/articles/hdr_color.html

648 27 0
MFCListCtrl
C++ 使用regex正则表达式
benojan 2024-3-7

C++ 使用regex正则表达式

案例 #include <iostream> #include <regex> using namespace std; int main() { string str{ "ang1\tm1-n1-ng1 ang1" }; regex e{ "(^|[ \\-\\s])([mn])(g*)1" }; cout << regex_replace(str, e, "$1$2$3"); }

716 27 0
正则表达式regex
C语言
benojan 2023-12-20

C语言

C编程常用 EXIT_SUCCESS // 退出成功 EXIT_FAILURE // 推出失败

457 27 0
c语言静态库、动态库制作
benojan 2023-11-30

c语言静态库、动态库制作

静态库制作及步骤 将 .c 生成 .o 文件 gcc -c add.c -o add.o 使用 ar 工具,制作静态库 ar rcs lib库名.a add.o sub.o div.o 编译静态库到可执行文件中 gcc test.c lib库名.a -o a.out 动态库制作及使用步骤 将 .c 生成 .o 文件 gcc -c add.c -o add.o -fPIC 使用 gcc -shared 制作动态库 gcc -shared lib库名.so add.o sub.o div.o 编译可执行文件,指定所使用的动态库 -l 指定库名 -L 指定库路径 gcc test.c -o a.out -l库名 -L./lib -I./inc 运行程序前的准备 export LD_LIBRARY_PATH=./lib 运行

532 27 0
关于C++里的查询
benojan 2023-11-27

关于C++里的查询

一、str.find() 在字符串str中查询子串的位置 #include <iostream> using namespace std; int main() { string str = "abcdefg"; size_t pos = str.find("bcd"); if(pos != string::npos) { // string::npos cout << pos << endl; // pos 为 1 } } 二、str.find_first_of() 在字符串str中查询字符的位置 #include <iostream> using namespace std; int main() { string str = "abcdefg"; size_t pos = str.find_first_of("bcd"); // 查询 'b' || 'c' || 'd' 在 str 的第一个位置 if(pos != string::npos) { // string::npos cout << pos << endl; // pos 为 1 } } 三、find() 在指定范围内,查询元素的位置(一般为有迭代器的对象或容器) #include <iostream> #include <algorithm> using namespace std; int main() { string str = "abcdef"; string::iterator pos = find(str.begin(), str.end(), 'b'); if (pos != str.end()) { cout << *pos << endl; } } 四、find_if() 在指定范围内,查询符合条件的元素的位置(一般为有迭代器的对象或容器) #include <iostream> #include <algorithm> using namespace std; template <typename T> class condition { public: condition(const T& str): m_str(str) {}; bool operator()(const T& str) { if(str > m_str) return true; return false; } private: T m_str; }; int main() { string str = "abcdefg"; string::iterator pos = find_if(str.begin(), str.end(), condition('b')); if (pos != str.end()) { cout << *pos << endl; } }

416 27 0
boost的字符串操作
benojan 2023-2-9

boost的字符串操作

头文件 #include <boost/algorithm/string.hpp> 功能 字符串切割 boost::algorithm::split() using namespace boost::algorithm; int main() { std::string s = "Boost C++ Libraries"; std::vector<std::string> v; split(v, s, is_space()); std::cout << v.size() << std::endl; } // 内置的方式 using algorithm::is_classified; using algorithm::is_space; // 空白 using algorithm::is_alnum; // 数字+字母 using algorithm::is_alpha; // 字母 using algorithm::is_cntrl; using algorithm::is_digit; // 数字 using algorithm::is_graph; using algorithm::is_lower; // 小写字母 using algorithm::is_upper; // 大写字母 using algorithm::is_print; using algorithm::is_punct; using algorithm::is_xdigit; using algorithm::is_any_of; // 字符串中的任意字符 using algorithm::is_from_range; 去除首尾字符-默认为空白字符 boost::algorithm::trim_left_copy(str) boost::algorithm::trim_right_copy(str) boost::algorithm::trim_copy(str) // 指定字符 boost::algorithm::trim_left_copy_if(str, boost::algorithm::is_any_of("+-") boost::algorithm::trim_right_copy_if(str, boost::algorithm::is_any_of("+-"))) boost::algorithm::trim_copy_if(str, boost::algorithm::is_any_of(" \t\n")) 大小写转换 boost::algorithm::to_upper(str) boost::algorithm::to_lower(str) // copy函数返回一个大小写变换之后的副本 boost::algorithm::to_upper_copy(str) boost::algorithm::to_upper_copy(str) 移除指定字符串 // 移除第一个出现的指定字符串 erase_first_copy(str, "strOrChar") // 移除第n个出现的指定字符串 erase_nth_copy(str, "strOrChar", 0) // 移除最后出现的指定字符串 erase_last_copy(str, "strOrChar") // 移除所有出现的指定字符串 erase_all_copy(str, "strOrChar") // 移除头部的指定字符串 erase_head_copy(str, 5) // 移除尾部的指定字符串 erase_tail_copy(str, 5) 查找子串 boost::algorithm::find_first(str, "substr") boost::algorithm::find_last() boost::algorithm::find_nth() boost::algorithm::find_head() boost::algorithm::find_tail() 字符串拼接 boost::algorithm::join() using namespace boost::algorithm; int main() { std::vector<std::string> v{"Boost", "C++", "Libraries"}; std::cout << join(v, " ") << std::endl; } 字符串替换 boost::algorithm::replace_first_copy(s, "B", "D") boost::algorithm::replace_nth_copy(s, "i", 0, "D") boost::algorithm::replace_last_copy(s, "i", "D") boost::algorithm::replace_all_copy(s, "i", "D") boost::algorithm::replace_head_copy(s, 5, "DoAAA") boost::algorithm::replace_tail_copy(s, 8, "BecCCC")

910 27 0
c++boost字符串操作
  1. 1
  2. 2
  3. 尾页

搜索

搜索历史 清空

最新评论

标签

  • 重写
  • 继承
  • 虚函数
  • springboot
  • java
  • drf
  • 私服
  • 脚本
  • Windows窗口程序
  • cmake
  • dll
  • Modeless
  • Accelerators
  • WTL
  • ListCtrl
  • MFC
  • regex
  • 正则表达式
  • 虚拟环境
  • venv
  • radio
  • html
  • vim
  • nodejs
  • Linux
  • 宝塔面板
  • bt
  • chatGPT
  • AI
  • turtle
  • python
  • 我的世界
  • api
  • bukkit
  • 字符串操作
  • docker
  • 本地架设
  • 游戏
  • 编程
  • CodeCombat
  • 教程
  • 插件开发
  • Minecraft
  • GBK
  • Unicode
  • UTF-8
  • 字符集
  • 转换
  • 编码
  • boost

链接

  • 標準吳語字典
  • 台州方言維基
  • 溫嶺吳語微辭典
关于 友链 rss
Powered by benojan

备案号: