C++中,宽窄字符互换(wchar_t char wstring string互换)

宽字符转窄字符(wstring转string): std::string WstringToString(const std::wstring& sInput) { if (sInput.length() == 0) return ""; int iBufLen = WideCharToMultiByte(CODE_PAGE, 0, sInput.c_str(), -1, NULL, 0, NULL, NULL); char* buf = new char[iBufLen + 1]; int iLen = WideCharToMultiByte(CODE_PAGE, 0, sInput.c_str(), -1, buf, iBufLen + 1, NULL, NULL); std::string sOutput(buf, iLen); delete[] buf; return sOutput; } 窄字符转宽字符(string转wstring): std::wstring utils::StringToWstring(const std::string& sInput) { if (sInput.length() == 0) return L""; int iBufLen = MultiByteToWideChar(CODE_PAGE, 0, sInput.c_str(), -1, NULL, 0); wchar_t* buf = new wchar_t[iBufLen + 1]; int iLen = MultiByteToWideChar(CODE_PAGE, 0, sInput.c_str(), -1, buf, iBufLen + 1); std::wstring sOutput(buf, iLen); delete[] buf; return sOutput; } 其中,涉及到wchar_t,char_t的转换,可由上面的函数修改一二可得。

2025-01-24 · 1 min · silomens

flask调用接口报404

近日玩flask框架,写了个简易的测试代码并使用postman调用,发现python报404: 一般来说,python报404,IP端口应该没问题。乍一看也没啥问题。后面注意到warning,使用pywsgi,如下图,其余不变,问题顺利解决:

2024-06-27 · 1 min · silomens

pip换源记录

记录一下 pip安装flask,显示WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)’: /simple/flask/ 解决方案:换源 pip install flask -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

2024-06-27 · 1 min · silomens

papermod(hugo框架)博客搭建

最近心血来潮,想在自己网站上搭建一个博客。看了很久,发现有hugo框架可用。但众所周知hugo是静态框架,编写的文章需要以md文件上传到服务器才可加载。故心念一计,不如写一个程序同步本地文章到服务器和博客园。于是就需要将hugo部署在服务器方便后续操作。 (PS:hugo一般部署在本地电脑上,生成静态文件后上传到服务器即可使用,但写一篇文章就要重新生成传上去过于麻烦…) 本文使用机器:CentOS 7 1、安装hugo 1.1 安装go 官网下载对应系统的文件并传到server(或者wget)(此处笔者下载了go1.22.4.linux-amd64.tar.gz):https://golang.google.cn/dl/ 解压文件(笔者解压至/usr/bin/go),配置profile 查看是否成功: 1.2 下载hugo预编译文件 链接:https://github.com/gohugoio/hugo/releases/tag/v0.127.0 根据官网推荐,放在/usr/local/bin 验证: 2、安装主题 2.1 新建站点 执行:hugo new site 此处笔者放在/root/blogs,但该目录极不推荐 2.2 下载PaperMod 链接:https://github.com/adityatelange/hugo-PaperMod/wiki/Installation 官方提供多种方式安装,可使用git也可直接下载zip。由于此时服务器访问GitHub过慢,笔者下载zip并传上去。将下载的文件解压到/root/blogs/theme/PaperMod即可(根据自己实际路径进行解压) 2.3 配置并测试 打开/root/blogs/hugo.yaml文件,配置如下(网址,标题看自己而定,但必须包含 theme: PaperMod,系统才能读取主题) 之后,在/root/blogs处输入hugo即可生成静态网页文件。将静态网页文件放至网站目录下即可访问:

2024-06-11 · 1 min · silomens