![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
jota
这个作者很懒,什么都没留下…
展开
-
windows 实现UDP广播获取设备
关键逻辑1、获取本机所有IP,把IP的最后一个字段值改为255,去掉重复的IP2、遍历所有IP进行广播代码实现// BroadcastDemo.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <stdio.h> #include <winsock2.h> #include <ws2tcpip.h> #include <ws2def.h>#pragma comment(l原创 2020-06-18 16:27:17 · 956 阅读 · 0 评论 -
UTF8和ANSI互转
std::string Utf8ToAnsi(const char* szUtf8){ bool bNeedFreeW = false; int WLength = MultiByteToWideChar(CP_UTF8, 0, szUtf8, -1, NULL, NULL); LPWSTR pszW = NULL; __try { pszW = (LPWSTR)_alloca((WLength + 1) * sizeof(WCHAR)); } __except (EXCEPTION..原创 2020-05-09 15:07:31 · 2749 阅读 · 1 评论 -
unsigned char*转string或QString
在使用libevent开发Http服务接收数据的过程中,发现返回的是unsigned char*,默认的编码UTF-8,如果转为正确的内容呢?1. unsigned char*转stringunsigned char* pBuf = evbuffer_pullup(req->input_buffer, -1);vector<unsigned char> vctB...原创 2019-11-06 09:37:46 · 4493 阅读 · 0 评论 -
调用sqlite3示例
这是以静态链接lib方式实现的调用,dll方式待更新 1.从官网下载源码https://sqlite.org/download.html我下载的是:2.下载后创建.lib静态库项目,把解压后的文件中的3个扔到新建的项目然后可以直接编译,但是会报错。3.修改项目属性,改为:不使用编译头然后再重新编译4.新建项目sqlite_demo,把sqli...原创 2019-10-15 11:03:27 · 238 阅读 · 0 评论 -
MFC 仿百度搜索
一、简述因为要在项目中一个搜索的功能,完成后把功能抽出来写成了一个独立的|Demo。因为这个Demo比较独立,所以抽出来的过程中支持拖拽搜索结果的功能就丢掉了,重点关注搜索的功能。1、功能亮点(1)支持中英文搜索、全拼搜索(精确搜索)、简拼搜索;(2)支持简单日志输出;(3)支持对搜索结果进行翻页。2、关键技术要点(1)汉字转拼音,详细实现请参考 https://blo...原创 2018-11-08 17:32:24 · 659 阅读 · 0 评论 -
获取当前系统登录用户名(包括以管理员权限启动也能获取到)
当程序以管理员权限启动后,如果需要获取当前系统登录非管理员用户名,大部分方法(如 GetUserName)获取到的都是管理员的用户名,以下是获取当前登录用户方法。直接上代码:#include <windows.h>#include <WtsApi32.h>#pragma comment(lib, "WtsApi32.lib")#include <str...原创 2019-01-24 14:56:03 · 11116 阅读 · 1 评论 -
VS2017开发基于Boost的Linux项目编译报错:对‘boost::system::system_category()’未定义的引用
问题:1>C:\Users\Administrator\Desktop\LinuxCmdDemo\LinuxBoostTcpClient\obj\x64\Debug\main.o:在函数‘boost : error : system::error_code::error_code()’中:1>/usr/local/include/boost/system/error_code.h...原创 2019-02-14 13:51:07 · 5330 阅读 · 0 评论 -
time_t 在英文操作系统获取的当前时间戳不对
问题:time_t在英文操作系统且系统时区为东八区之前的时区,获取的“当前时间戳”比实际当前时间戳少了3600秒代码如下:方式一是有bug的方法方式二是正常的方法// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <string>#include <iost...原创 2019-04-07 17:58:43 · 1740 阅读 · 0 评论 -
时间戳和时间字符串互转
#include <iostream>#include <string>#include <iomanip>using namespace std;// 时间字符串转时间戳time_t TimeStringToTimestamp(string strTime){ struct tm tmTime; sscanf(strTime.c_...原创 2019-06-10 16:49:33 · 3408 阅读 · 3 评论 -
QLineEdit实现可显示密码可隐藏密码
一、效果图二、关键逻辑QLineEditPassword.h#ifndef QLINEEDITPASSWORD_H#define QLINEEDITPASSWORD_H#include <QLineEdit>class QLineEditPassword : public QLineEdit{ Q_OBJECTpublic: ...原创 2019-07-31 15:53:50 · 3900 阅读 · 5 评论 -
QLineEdit 获得焦点后全选文本
void QLineEditEx::focusInEvent(QFocusEvent* event){ QLineEdit::focusInEvent(event); QTimer::singleShot(0, this, &QLineEdit::selectAll);}原创 2019-07-31 18:01:06 · 4402 阅读 · 1 评论 -
WIN32 根据进程名称关闭进程
#include <windows.h>#include <Tlhelp32.h>#include <sstream>// 根据进程名称获取进程IDDWORD GetProcessIDByName(const TCHAR* pName){ HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNA...原创 2019-09-17 16:17:56 · 781 阅读 · 0 评论 -
中文汉字转拼音
本文参考:https://www.cnblogs.com/superstargg/p/4460231.html一、简述因为要做一个搜索的功能,要支持中文、全拼、简拼搜索,而且搜索要准确。中文的搜索直接匹配,全拼的搜索就需要先把中文转成拼音,对于多音字也要兼容。下面是关于如何把中文转拼音的实现。目前知道实现方式有两种:(1)通过判断字符值来返回汉字,这种耗时少,但是不兼容多音字,后期...原创 2018-11-07 21:57:12 · 73661 阅读 · 0 评论 -
C++实现二分查找法
面试题1、请实现二分查找法 答:#include <iostream>using namespace std;const int g_nSize = 32;int FindValuePos(int (&arry)[g_nSize], int nValue){ int nLeft = sizeof(arry) / sizeof(int) / 2; int nPos = nLeft原创 2017-11-25 01:00:50 · 453 阅读 · 0 评论 -
对于CRITICAL_SECTION用法的介绍和理解
转载来源http://blog.sina.com.cn/s/blog_7953cead0100osnt.html 很多人对CRITICAL_SECTION的理解是错误的,认为CRITICAL_SECTION是锁定了资源,其实,CRITICAL_SECTION是不能够“锁定”资源的,它能够完成的功能,是同步不同线程的代码段。简单说,当一个线程执行了EnterCritialSec...转载 2017-02-05 17:55:31 · 30361 阅读 · 10 评论 -
对于C++锁的封装及使用
对于C++锁的封装及使用原创 2017-02-05 18:25:46 · 2640 阅读 · 0 评论 -
关于代码区域化的使用
#pragma region// To do something#pragma endregion原创 2017-03-01 15:11:41 · 462 阅读 · 0 评论 -
VS2008下编译C++程序,找不到 stdint.h,原因及解决方案
来源:http://www.cnblogs.com/verygis/archive/2012/04/22/2465561.html在 VS2008 下编译c++程序,发现找不到 stdint.h, 最后发现原因如下:Visual Studio 2003 - 2008 (Visual C++ 7.1 - 9) don't claim to be C99 compatible转载 2017-03-14 14:39:43 · 5873 阅读 · 1 评论 -
获取唯一ID的方法(保证线程安全)
获取唯一ID的方法(保证线程安全)原创 2017-08-14 08:34:21 · 1462 阅读 · 0 评论 -
C++临时打日志
1、更新(2019-12-02):支持流方式打简单日志#include <sstream>#include <atltime.h>#include <iomanip>#include <string>using namespace std;std::string GetExeDir(void){ char szFilePath...原创 2017-09-19 13:56:08 · 757 阅读 · 0 评论 -
C++实现string.replace(字符串替换)
#include "stdafx.h"#include <iostream>#include <string>using namespace std;void string_replace( std::string &strBig, const std::string &strsrc, const std::string &strdst);int _tmain(int argc, _TCHA原创 2017-10-28 16:40:06 · 25239 阅读 · 0 评论 -
C++根据文件路径获取文件名
#include "stdafx.h"#include <iostream>#include <string>using namespace std;std::string GetPathOrURLShortName(std::string strFullName);int _tmain(int argc, _TCHAR* argv[]){ std::string strFileP原创 2017-10-28 16:46:26 · 19535 阅读 · 0 评论 -
C++用libcurl通过HTTP以表单的方式Post数据到服务器
libcurl HTTP Post原创 2017-10-15 00:57:07 · 6719 阅读 · 0 评论 -
C++单例模式
C++中的单例模式一般分两种,一是饿汉单例模式,二是懒汉单例模式。其中懒汉单例模式本身保证线程安全,而饿汉单例模式需要加锁才能保证线程安全。并且,饿汉单例模式加锁后可以通过判断两次来提高性能,从而演化成双检测单例模式。下面用代码表达:一、饿汉单例模式Singleton_Eager.h#pragma oncenamespace Singleton_Eager{ // 饿汉单例模式(保...原创 2018-04-09 13:35:19 · 293 阅读 · 0 评论 -
C++友元类笔记
class CTeacher;class CStudent{ // 表示CStudent是CTeacher的友元类,在CTeacher中定义的CStudent对象 // 可以访问CStudent的private权限的成员变量。 friend class CTeacher; public: CStudent(); ~CStudent();private: int m_nStuNo;};CStude...原创 2018-06-23 09:34:07 · 233 阅读 · 0 评论 -
读写锁的基本理解及简单用法
一、需要材料:1.pthreads-w32-2-8-0-release.exe下载:ftp://sourceware.org/pub/pthreads-win32二、操作步骤:1.VS2008新建控制台项目#include #include #include #include #pragma comment(lib, "pthreadVC2.lib")原创 2016-11-20 17:08:08 · 3762 阅读 · 0 评论