随笔分类 - c++
摘要:之前写过一篇 Qt获取Windows系统的WIFI列表的文章,原理是通过cmd命令来实现的,现在发现直接调用Windows API会更简单,所以记录一下 Qt 获取WIFI列表:https://www.cnblogs.com/shiyixirui/p/17965357 代码: #include <w
阅读全文
摘要:用到的是Windows的SAPI,所以只支持Windows。 我测试了一百多个字符转音频导出,速度还挺快的,1秒不到就转好了。 #include <sapi.h> #include "sphelper.h" #include "atlbase.h" #pragma comment(lib,"ole3
阅读全文
摘要:1.支持重复安装 2.安装前关闭程序,避免覆盖失败 3.卸载前关闭程序,避免卸载失败 重点:使用终端命名杀死进程 ShellExec('open', ExpandConstant('{cmd}'), '/c taskkill /f /t /im hp.exe', '', SW_HIDE, ewNoW
阅读全文
摘要:重点: HPDF_UseCNSFonts(pdf); HPDF_UseCNSEncodings(pdf); HPDF_Font font = HPDF_GetFont(pdf, "SimSun", "GB-EUC-H"); 完整代码: #include "include/hpdf.h" #pragm
阅读全文
摘要:接口: MMRESULT timeSetEvent( UINT uDelay, // 以毫秒指定事件的周期 UINT uResolution, // 以毫秒指定延时的精度,缺省值为1ms LPTIMECALLBACK lpTimeProc, // 指向回调函数的指针 WORD dwUser, //
阅读全文
摘要:#include <iostream> using namespace std; struct A { virtual void func() { cout << "A func" << endl; } }; struct B :public A { void func() { cout << "B
阅读全文
摘要:推荐 filesystem ,特别好用,除了新建、删除、复制、移动文件夹,还支持磁盘空间检测,权限检测,路径处理。 一、使用系统库 // 检测文件,检测文件夹 /* windows * 头文件:io.h * 函数:int access(const char* _Filename, int _Acce
阅读全文
摘要:#include <iostream> #include <thread> #include <chrono> using namespace std; int main() { cout << "C++11" << endl; std::this_thread::sleep_for(std::ch
阅读全文
摘要:C++11 标准 #include <iostream> #include <random> using namespace std; int main() { cout << "C++11" << endl; default_random_engine random(time(nullptr));
阅读全文
摘要:一、执行简单命令 比如需要创建文件、文件夹、删除文件 #include <iostream> #include <stdio.h> #include <stdlib.h> int main() { // 执行简单的 shell 命令 std::string cmd = "mkdir heihei";
阅读全文
摘要:第一种方式,是直接查询设备的vid、pid文件,来获取vid,pid 第二种方式,是查询设备信息,自己去解析对应的vid和pid 正常情况下,第一种方式就可以了,但是今天遇到一个ARM架构的kylin系统,通过第一种方式来查询设备ID,报错,无vendor这个文件,然后看了下是否有其他的文件包含的有
阅读全文
摘要:libharu编译需要libpng,libpng依赖zlib,所以需要下载这三个库 libharu下载:http://libharu.org/ libpng下载:http://www.libpng.org/pub/png/libpng.html zlib下载:https://www.zlib.net
阅读全文
摘要:libharu官网:http://libharu.org/ 直接下载下来编译就可以使用了(*:我下载的版本是:libharu-libharu-v2.4.3-0-g8dbcfe4.tar) 一、编译 官方编译指导:https://github.com/libharu/libharu/wiki/Inst
阅读全文
摘要:前文: 最近有个项目,需要读写PDF,本来想着挺简单的,读写PDF有那么多的库可以使用,唰唰的就完成了。 忘记了我写C++的,还是在国产系统上开发的。 所以一般的东西还不好使,因为项目需要在多个架构的电脑上使用,所以必须要开源,还要支持读写才行。 找了很多个PDF库(libharu、mupdf、pd
阅读全文
摘要:C++ 单例模式有两种写法: 饿汉模式 和 懒汉模式 饿汉模式: 优点:对象提前创建好,使用的时候无需等待,效率高 缺点:对象提前创建,所以占用内存高 以空间占时间 懒汉模式: 优点:使用对象时,对象才创建,不会提前占用内存 缺点:首次使用对象时,需要等待对象的创建,效率低 以时间换空间 饿汉模式:
阅读全文
摘要:为了避免单例类在多线程中重复的创建,下面提供了两种解决方法: 1.互斥锁+双重检查 2.std::call_once() 方法一:互斥锁+双重检查 #include <iostream> #include <thread> #include <mutex> #include <list> using
阅读全文
摘要:#include <iostream> #include <thread> #include <mutex> #include <list> #include <future> using namespace std; int myThread(int num) { cout << "myThrea
阅读全文
摘要:*:如果 std::async 中传递参数 std::lunnch::deferred ,就需要等待调用 get() 或者 wait() 才会执行,并且代码非子线程运行,而是在主线程中执行 #include <iostream> #include <thread> #include <mutex>
阅读全文
摘要:condition_variable 、 wait 、 notify_one 、 notify_all *:notify_one:通知(唤醒)一个线程 *:notify_all:通知(唤醒)多个线程 #include <iostream> #include <thread> #include <mu
阅读全文
摘要:timed_mutex 、 try_lock_for 、 try_lock_until #include <iostream> #include <thread> #include <mutex> #include <list> using namespace std; class A { publ
阅读全文