他小的有http://www.suchone.com/杨明的个人博客他小的有http://www.suchone.com/post/55.html<p><strong><span style="font-size: 18px;">一、安装docker:</span></strong><br/></p><p><span style="font-size: 16px;"><strong>1.1 下载脚本</strong></span></p><pre class="brush:bash;toolbar:false">curl&nbsp;-fsSL&nbsp;https://get.docker.com&nbsp;-o&nbsp;get-docker.sh</pre><p><span style="font-size: 16px;"><strong>1.2 以阿里云镜像安装脚本内容</strong></span></p><pre class="brush:bash;toolbar:false">sh&nbsp;get-docker.sh&nbsp;--mirror&nbsp;Aliyun</pre><p><span style="font-size: 16px;"><strong>1.3 更换源</strong></span></p><pre class="brush:bash;toolbar:false">sudo&nbsp;nano&nbsp;/etc/docker/daemon.json</pre><pre class="brush:bash;toolbar:false">{ &nbsp;&nbsp;&quot;registry-mirrors&quot;:&nbsp;[&quot;https://registry.docker-cn.com&quot;] }</pre><p><strong><span style="font-size: 16px;">1.4 设定开机启动和重启</span></strong></p><pre class="brush:bash;toolbar:false">sudo&nbsp;systemctl&nbsp;enable&nbsp;docker&nbsp;#开机启动 sudo&nbsp;systemctl&nbsp;start&nbsp;docker&nbsp;#启动</pre><p><br/></p><p><span style="font-size: 18px;"><strong>二、安装 homeassistant +HASS</strong></span></p><p><strong><span style="font-size: 16px;">2.1 安装armhf-hassio-supervisor镜像:</span></strong></p><pre class="brush:bash;toolbar:false">sudo&nbsp;docker&nbsp;pull&nbsp;homeassistant/armhf-hassio-supervisor:latest</pre><p><span style="font-size: 16px;"><strong><span style="color: rgb(0, 0, 0);">2.2 安装armhf-homeassistant镜像</span></strong></span></p><pre class="brush:bash;toolbar:false">sudo&nbsp;docker&nbsp;pull&nbsp;homeassistant/armhf-homeassistant:latest</pre><p><strong><span style="font-size: 16px;">2.3 运行</span></strong></p><pre class="brush:bash;toolbar:false">sudo&nbsp;docker&nbsp;run&nbsp;-d&nbsp;\ &nbsp;--name=&quot;home-assistant&quot;&nbsp;\ &nbsp;-v&nbsp;/home/pi/homeassistant:/config&nbsp;\ &nbsp;-v&nbsp;/etc/localtime:/etc/localtime:ro&nbsp;\ &nbsp;--net=host&nbsp;\ &nbsp;--restart=always&nbsp;\ &nbsp;homeassistant/armhf-homeassistant</pre><p><br/></p>Tue, 29 Dec 2020 21:32:29 +0800他小的有http://www.suchone.com/post/53.html<p><strong style="font-size: 20px;">准备软件:</strong><br/></p><p><strong><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 18px; text-align: justify; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;1.SD Card Formatter:</span></strong><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 18px; text-align: justify; background-color: rgb(255, 255, 255);"><a href="https://www.sdcard.org/downloads/formatter/eula_windows/SDCardFormatterv5_WinEN.zip" rel="nofollow" target="_blank" title="SDCardFormatterv5_WinEN.zip">SDCardFormatterv5_WinEN.zip</a><span style="font-size: 18px;">(格式化TF卡工具)</span></span></p><p><strong><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 18px; text-align: justify; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;2.Win32DiskImager:</span></strong><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 18px; text-align: justify; background-color: rgb(255, 255, 255);"><a href="https://win32diskimager.download/Win32DiskImager-1.0.0-src.zip" rel="nofollow" rel="nofollow" target="_blank" title="Win32DiskImager-1.0.0-src.zip">Win32DiskImager-1.0.0-src.zip</a><span style="font-size: 18px;">(系统镜像烧录工具)</span></span></p><p><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 18px; text-align: justify; background-color: rgb(255, 255, 255);"><a href="https://win32diskimager.download/Win32DiskImager-1.0.0-src.zip" rel="nofollow" rel="nofollow" target="_blank" title="Win32DiskImager-1.0.0-src.zip"></a></span>&nbsp; <span style="font-size: 18px;">&nbsp;<strong> 3.Raspberry Pi OS:</strong></span><a href="https://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os-images/raspios_full_armhf/images/raspios_full_armhf-2020-12-04/2020-12-02-raspios-buster-armhf-full.zip" rel="nofollow" target="_blank" title="2020-12-02-raspios-buster-armhf-full.zip" style="font-size: 18px; white-space: normal;">2020-12-02-raspios-buster-armhf-full.zip</a><span style="font-size: 18px;">(树莓派官方系统,第一次使用建议下载完整桌面版)</span></p><p>&nbsp; &nbsp; <strong><span style="font-size: 18px;">4.Putty:<a href="https://the.earth.li/~sgtatham/putty/0.74/w64/putty-64bit-0.74-installer.msi" rel="nofollow" rel="nofollow" target="_blank" title="putty-64bit-0.74-installer.msi"></a></span></strong><span style="font-size: 18px;"><a href="https://the.earth.li/~sgtatham/putty/0.74/w64/putty-64bit-0.74-installer.msi" rel="nofollow" rel="nofollow" target="_blank" title="putty-64bit-0.74-installer.msi">putty-64bit-0.74-installer.msi</a>(SSH远程工具)</span></p><p><strong><span style="font-size: 16px;">第一步:将TF卡插入读卡器并插入电脑,使用<strong style="white-space: normal;"><span style="color: rgb(51, 51, 51); font-family: arial; text-align: justify; background-color: rgb(255, 255, 255);">SD Card Formatter工具进行</span></strong>格式化TF卡</span></strong></p><p><span style="font-size: 16px;"><strong><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609157859431692.png" title="正在上传..." alt="image.png"/></strong></span></p><p><span style="font-size: 16px;"><strong><br/></strong></span></p><p><span style="font-size: 16px;"><strong>第二步:<strong style="font-size: 16px; white-space: normal;">下载树莓派系统并解压,解压之后得到一个.img文件,使用<strong style="white-space: normal;"><span style="color: rgb(51, 51, 51); font-family: arial; font-size: 18px; text-align: justify; background-color: rgb(255, 255, 255);">Win32DiskImager</span></strong></strong>将该文件并烧录到TF卡中,写入完成时系统可能提示需要格式化,此时不要格式化</strong></span></p><p><span style="font-size: 16px;"><strong><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609157974534300.png" title="正在上传..." alt="image.png"/></strong></span></p><p><span style="font-size: 16px;"><strong><br/></strong></span></p><p><span style="font-size: 16px;"><strong>第三步:为了能让系统开机之后自动连线WIFI,需要新建一个wpa_supplicant.conf文件,并填入以下内容,复制到<strong style="font-size: 16px; white-space: normal;">boot</strong>根目录</strong></span></p><pre class="brush:bash;toolbar:false">ctrl_interface=DIR=/var/run/wpa_supplicant&nbsp;GROUP=netdev update_config=1 country=CN network={ ssid=&quot;WIFI名称&quot; psk=&quot;WIFI密码&quot; key_mgmt=WPA-PSK priority=10 }</pre><p><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609158579434275.png" title="正在上传..." alt="image.png"/></p><p><br/></p><p><span style="font-size: 16px;"><strong>第四步:默认情况下树莓派是关闭SSH的,需要新增一个ssh文件(不要带后缀)并放入boot根目录让其开机时打开SSH以便连接,然后<strong style="font-size: 16px; white-space: normal;">将TF卡从读取卡器取出并插入树莓中,启动树莓派</strong></strong></span></p><p><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609159234600804.png" title="正在上传..." alt="image.png"/></p><p><br/></p><p><span style="font-size: 16px;"><strong>第五步:打开路由器查看树莓派连接的IP地址,使用Putty工具进行连接,默认用户名:pi,密码:raspberry,输入密码时看不到字符变化,输入完毕回车即可</strong></span></p><p><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609159373918433.png" title="正在上传..." alt="image.png"/></p><p><span style="font-size: 16px;"><strong><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609159574546064.png" title="正在上传..." alt="image.png"/></strong></span></p><p><span style="font-size: 16px;"><strong><br/></strong></span></p><p><span style="font-size: 16px; color: rgb(0, 0, 0);"><strong>至此整个树莓派系统安装就完成了。</strong></span></p><p><strong style="font-size: 16px;"></strong><br/></p><p><span style="font-size: 16px;"><strong>树莓派默认使用的国外的源,访问速度较慢,这里建议更换为清华大学开源软件镜像站,使用管理员权限,编辑/etc/apt/sources.list文件</strong></span></p><pre class="brush:bash;toolbar:false">sudo&nbsp;nano&nbsp;/etc/apt/sources.list</pre><p><span style="color: rgb(0, 0, 0);"><strong><span style="font-size: 16px; font-variant-ligatures: common-ligatures; text-align: justify; background-color: rgb(255, 255, 255); font-family: &quot;Microsoft YaHei&quot;;">用#注释掉原文件内容,并在最后添加如下内容(建议直接复制粘贴避免拼写错误)</span></strong></span></p><pre class="brush:bash;toolbar:false">deb&nbsp;http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/&nbsp;buster&nbsp;main&nbsp;non-free&nbsp;contrib deb-src&nbsp;http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/&nbsp;buster&nbsp;main&nbsp;non-free&nbsp;contrib</pre><p><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609161889845673.png" title="正在上传..." alt="image.png"/><span style="font-size: 16px;"></span></p><p><strong style="font-size: 16px; white-space: normal;">使用管理员权限,编辑/etc/apt/sources.list.d/raspi.list文件</strong></p><pre class="brush:bash;toolbar:false">sudo&nbsp;nano&nbsp;/etc/apt/sources.list.d/raspi.list</pre><p><strong style="white-space: normal;"><span style="font-size: 16px; font-variant-ligatures: common-ligatures; text-align: justify; background-color: rgb(255, 255, 255); font-family: &quot;Microsoft YaHei&quot;;">用#注释掉原文件内容,并在最后添加如下内容(建议直接复制粘贴避免拼写错误)</span></strong></p><pre class="brush:bash;toolbar:false">deb&nbsp;http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/&nbsp;buster&nbsp;main&nbsp;ui</pre><p><img src="http://www.suchone.com/zb_users/upload/2020/12/202012281609161978935648.png" title="正在上传..." alt="image.png"/></p><p><strong style="white-space: normal; font-size: 16px;"><span style="color: rgb(79, 79, 79); font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 16px; font-variant-ligatures: common-ligatures; text-align: justify; background-color: rgb(255, 255, 255);"><br/></span></strong></p><p><span style="font-family: &quot;Microsoft YaHei&quot;;"><strong style="white-space: normal; font-size: 16px;"><span style="color: rgb(79, 79, 79); font-size: 16px; font-variant-ligatures: common-ligatures; text-align: justify; background-color: rgb(255, 255, 255);">然后按下Ctrl+X退出,会提示是否需要保存,输入y然后回车确定即可</span></strong></span></p><p><strong style="white-space: normal; font-size: 16px;"><span style="color: rgb(79, 79, 79); font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 16px; font-variant-ligatures: common-ligatures; text-align: justify; background-color: rgb(255, 255, 255);"><br/></span></strong></p><p><span style="font-family: &quot;Microsoft YaHei&quot;; color: rgb(0, 0, 0);"><strong style="white-space: normal; font-size: 16px;"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 16px; font-variant-ligatures: common-ligatures; text-align: justify; background-color: rgb(255, 255, 255);">最后执行更新</span></strong></span></p><pre class="brush:bash;toolbar:false">sudo&nbsp;apt-get&nbsp;update sudo&nbsp;apt-get&nbsp;upgrade</pre><p>第一句<span style="margin: 0px; padding: 0px; background-color: rgb(255, 255, 255); color: rgb(69, 69, 69); font-family: Tahoma, Helvetica, Arial, STHeiti; line-height: 21px;">是更新你的源列表,</span><span style="margin: 0px; padding: 0px; background-color: rgb(255, 255, 255); color: rgb(69, 69, 69); font-family: Tahoma, Helvetica, Arial, STHeiti; line-height: 21px;">换源后必须执行。</span></p><p><span style="margin: 0px; padding: 0px; background-color: rgb(255, 255, 255); color: rgb(69, 69, 69); font-family: Tahoma, Helvetica, Arial, STHeiti; line-height: 21px;">第二句为<span style="color: rgb(69, 69, 69); font-family: Tahoma, Helvetica, Arial, STHeiti; background-color: rgb(255, 255, 255);">是更新软件,如果你对新版本软件的需求不是那么迫切,可以不执行。</span></span></p><p><br/></p><p><strong><span style="font-size: 18px;">其它:</span></strong></p><p><span style="font-size: 18px;">修改时区:</span></p><pre class="brush:bash;toolbar:false">sudo&nbsp;timedatectl&nbsp;set-timezone&nbsp;Asia/Shanghai</pre><p><br/></p><p><strong><span style="font-size: 18px;">结束!</span></strong></p>Sun, 27 Dec 2020 23:32:00 +0800他小的有http://www.suchone.com/post/52.html<p>&nbsp;&nbsp;&nbsp;&nbsp;发布软件时,需要修改.rc文件的yabo亚搏手机最新版app再编译工程,以便于当模块出现问题快速确定所使用模块的yabo亚搏手机最新版app,可使用Python在编译前进行自动修改yabo亚搏手机最新版app再编译发布:</p><p>&nbsp;&nbsp;&nbsp;&nbsp;//util_modify_rc_file_version.py</p><pre class="brush:python;toolbar:false">#&nbsp;modify&nbsp;.rc&nbsp;file&nbsp;version import&nbsp;sys,re if&nbsp;__name__==&quot;__main__&quot;: &nbsp;&nbsp;&nbsp;&nbsp;filename&nbsp;=&nbsp;sys.argv[1] &nbsp;&nbsp;&nbsp;&nbsp;version&nbsp;=&nbsp;sys.argv[2] &nbsp;&nbsp;&nbsp;&nbsp;versionMacro&nbsp;=&nbsp;version.replace(&#39;.&#39;,&nbsp;&#39;,&#39;) &nbsp;&nbsp;&nbsp;&nbsp;versionString&nbsp;=&nbsp;version.replace(&#39;,&#39;,&nbsp;&#39;.&#39;) &nbsp;&nbsp;&nbsp;&nbsp;filename&nbsp;=&nbsp;filename.replace(&quot;\\\\&quot;,&quot;\\&quot;) &nbsp;&nbsp;&nbsp;&nbsp;f&nbsp;=&nbsp;open(filename,&nbsp;&#39;r&#39;,&nbsp;encoding=&#39;utf-16&#39;) &nbsp;&nbsp;&nbsp;&nbsp;lines&nbsp;=&nbsp;f.readlines() &nbsp;&nbsp;&nbsp;&nbsp;newLines&nbsp;=&nbsp;[] &nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;line&nbsp;in&nbsp;lines: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;line.startswith(&#39;&nbsp;FILEVERSION&nbsp;&#39;): &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;=&nbsp;&#39;&nbsp;FILEVERSION&nbsp;&#39;&nbsp;+&nbsp;versionMacro&nbsp;+&nbsp;&#39;\n&#39; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;line.startswith(&#39;&nbsp;PRODUCTVERSION&nbsp;&#39;): &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;=&nbsp;&#39;&nbsp;PRODUCTVERSION&nbsp;&#39;&nbsp;+&nbsp;versionMacro&nbsp;+&nbsp;&#39;\n&#39; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;=&nbsp;re.sub(&nbsp;r&#39;(\s+VALUE\s&quot;FileVersion&quot;,\s+)&quot;(.*)&quot;&#39;,r&#39;\1&quot;%s&quot;&#39;&nbsp;%&nbsp;versionString,&nbsp;line) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;=&nbsp;re.sub(&nbsp;r&#39;(\s+VALUE\s&quot;ProductVersion&quot;,\s+)&quot;(.*)&quot;&#39;,r&#39;\1&quot;%s&quot;&#39;&nbsp;%&nbsp;versionString,&nbsp;line) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newLines.append(line) &nbsp;&nbsp;&nbsp;&nbsp;f.close() &nbsp;&nbsp;&nbsp;&nbsp;f&nbsp;=&nbsp;open(filename,&nbsp;&#39;w&#39;,&nbsp;encoding=&#39;utf-16&#39;) &nbsp;&nbsp;&nbsp;&nbsp;f.writelines(newLines) &nbsp;&nbsp;&nbsp;&nbsp;f.close()</pre><p>&nbsp;&nbsp;&nbsp;&nbsp;示例:</p><pre class="brush:python;toolbar:false">python&nbsp;&quot;C:\util_modify_rc_file_version.py&quot;&nbsp;&quot;C:\demo.rc&quot;&nbsp;&quot;1.2.3.4&quot;</pre><p>&nbsp; &nbsp; 说明:传入的第一个参数是要修改的.rc文件路径,第二个参数是yabo亚搏手机最新版app<br/></p><p>&nbsp;&nbsp;&nbsp;&nbsp;其它:配合Jenkins在发布时自动修改yabo亚搏手机最新版app效果更佳,一劳永逸 :)<br/></p><p><span style="font-size: 16px;"><strong><span style="background-color: rgb(255, 255, 255); color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;注意:我当前使用的是VS2015生成的.rc文件默认编码是utf-16 little endian,其它编码请自行修改打开和保存.rc文件的编码,另外要在执行这个脚本修改.rc文件版本后再编译项目哟~</span></strong></span></p>Sat, 31 Oct 2020 17:29:34 +0800他小的有http://www.suchone.com/post/51.html<p><span style="font-size: 18px;"><strong>1.如果是命令行的方式,在执行命令前先执行</strong></span></p><pre class="brush:bash;toolbar:false">chcp&nbsp;65001</pre><p><br/></p><p><strong><span style="font-size: 18px;">2.通过system命令修改编码</span></strong></p><pre class="brush:cpp;toolbar:false">#include&nbsp;&quot;stdafx.h&quot; #include&nbsp;&lt;Windows.h&gt; #include&nbsp;&lt;iostream&gt; int&nbsp;main() { &nbsp;&nbsp;&nbsp;&nbsp;system(&quot;chcp&nbsp;65001&quot;); &nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;u8&quot;中华人民共和国&quot;&nbsp;&lt;&lt;&nbsp;std::endl; &nbsp;&nbsp;&nbsp;&nbsp;std::system(&quot;pause&quot;); &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0; }</pre><p><span style="color: rgb(255, 0, 0); font-size: 16px;">缺点:会额外输出 Active code page: 65001&nbsp;字符串。</span><br/></p><p><br/></p><p><strong><span style="font-size: 18px;">3.通过SetConsoleOutputCP函数修改编码</span></strong></p><pre class="brush:cpp;toolbar:false;">#include&nbsp;&quot;stdafx.h&quot; #include&nbsp;&lt;Windows.h&gt; #include&nbsp;&lt;iostream&gt; int&nbsp;main() { &nbsp;&nbsp;&nbsp;&nbsp;SetConsoleOutputCP(CP_UTF8); &nbsp;&nbsp;&nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;u8&quot;中华人民共和国&quot;&nbsp;&lt;&lt;&nbsp;std::endl; &nbsp;&nbsp;&nbsp;&nbsp;std::system(&quot;pause&quot;); &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;0; }</pre>Sat, 11 Jul 2020 15:07:25 +0800他小的有http://www.suchone.com/post/50.html<p style="text-indent: 2em;">字符串乱码往往是由于编码不一致或编码没有对应的字符所致,为了能够正常显示字符串,经常会有需要编码转换的需要,为了方便使用这里整理成一个head-only文件,这里提供了char、wchar_t、utf-8之间的转换,在实际的项目中建议使用wchar_t/utf-8,强烈建议使用utf-8。</p><p style="text-indent: 2em;"><span style="color: rgb(255, 0, 0);">//ZEncode.hpp</span></p><pre class="brush:cpp;toolbar:false">#pragma&nbsp;once #include&nbsp;&lt;Windows.h&gt; #include&nbsp;&lt;string&gt; #include&nbsp;&lt;vector&gt; #include&nbsp;&lt;assert.h&gt; /*! &nbsp;*&nbsp;编码转换命名空间 &nbsp;*&nbsp; &nbsp;*/ namespace&nbsp;ZEncode { /*! &nbsp;*&nbsp;窄字节转宽字节 &nbsp;*&nbsp; &nbsp;*&nbsp;\param&nbsp;str&nbsp;窄字节 &nbsp;*&nbsp;\param&nbsp;uCodePage&nbsp;窄字节编码 &nbsp;*&nbsp;\return&nbsp;宽字节 &nbsp;*/ static&nbsp;std::wstring&nbsp;A2W(const&nbsp;std::string&nbsp;&amp;str,&nbsp;UINT&nbsp;uCodePage) { int&nbsp;nLength&nbsp;=&nbsp;::MultiByteToWideChar(uCodePage,&nbsp;0,&nbsp;str.c_str(),&nbsp;-1,&nbsp;NULL,&nbsp;0); if&nbsp;(0&nbsp;==&nbsp;nLength) { throw&nbsp;std::exception(&quot;A2W&nbsp;Error&quot;); } std::wstring&nbsp;strW(nLength,&nbsp;L&#39;\0&#39;); int&nbsp;nResult&nbsp;=&nbsp;::MultiByteToWideChar(uCodePage,&nbsp;0,&nbsp;str.c_str(),&nbsp;-1,&nbsp;&amp;strW[0],&nbsp;nLength); if&nbsp;(nResult&nbsp;!=&nbsp;nLength) { throw&nbsp;std::exception(&quot;A2W&nbsp;Error&quot;); } strW.resize(nLength&nbsp;-&nbsp;1); return&nbsp;strW; } /*! &nbsp;*&nbsp;宽字节转窄字节 &nbsp;*&nbsp; &nbsp;*&nbsp;\param&nbsp;str&nbsp;宽字节 &nbsp;*&nbsp;\param&nbsp;uCodePage&nbsp;窄字节编码 &nbsp;*&nbsp;\return&nbsp;窄字节 &nbsp;*/ static&nbsp;std::string&nbsp;W2A(const&nbsp;std::wstring&nbsp;&amp;str,&nbsp;UINT&nbsp;uCodePage) { int&nbsp;nLength&nbsp;=&nbsp;::WideCharToMultiByte(uCodePage,&nbsp;0,&nbsp;str.c_str(),&nbsp;-1,&nbsp;NULL,&nbsp;0,&nbsp;NULL,&nbsp;NULL); if&nbsp;(0&nbsp;==&nbsp;nLength) { throw&nbsp;std::exception(&quot;W2A&nbsp;Error&quot;); } std::string&nbsp;strA(nLength,&nbsp;&#39;\0&#39;); int&nbsp;nResult&nbsp;=&nbsp;::WideCharToMultiByte(uCodePage,&nbsp;0,&nbsp;str.c_str(),&nbsp;-1,&nbsp;&amp;strA[0],&nbsp;nLength,&nbsp;NULL,&nbsp;NULL); if&nbsp;(nResult&nbsp;!=&nbsp;nLength) { throw&nbsp;std::exception(&quot;W2A&nbsp;Error&quot;); } strA.resize(nLength&nbsp;-&nbsp;1); return&nbsp;strA; } /*! &nbsp;*&nbsp;窄字节转窄字节 &nbsp;*&nbsp; &nbsp;*&nbsp;\param&nbsp;str&nbsp;窄字节 &nbsp;*&nbsp;\param&nbsp;uCodePageFrom&nbsp;源始字节编码 &nbsp;*&nbsp;\param&nbsp;uCodePageTo&nbsp;目标字节编码 &nbsp;*&nbsp;\return&nbsp;窄字节 &nbsp;*/ static&nbsp;std::string&nbsp;A2A(const&nbsp;std::string&nbsp;&amp;str,&nbsp;UINT&nbsp;uCodePageFrom,&nbsp;UINT&nbsp;uCodePageTo) { return&nbsp;W2A(A2W(str,&nbsp;uCodePageFrom),&nbsp;uCodePageTo); } /*! &nbsp;*&nbsp;检查缓冲区数据是否是UTF-8 &nbsp;*&nbsp; &nbsp;*&nbsp;\param&nbsp;pBuffer&nbsp;缓冲区 &nbsp;*&nbsp;\param&nbsp;size&nbsp;大小 &nbsp;*&nbsp;\return&nbsp;如果是返回true,否则返回false。 &nbsp;*&nbsp; &nbsp;*&nbsp;\note&nbsp;返回结果并不一定完全正确,仅作为一个参考用途。 &nbsp;*/ static&nbsp;bool&nbsp;IsUTF8(const&nbsp;void*&nbsp;pBuffer,&nbsp;size_t&nbsp;size) { //参考&nbsp;http://blog.csdn.net/bladeandmaster88/article/details/54767487 bool&nbsp;bIsUTF8&nbsp;=&nbsp;true; unsigned&nbsp;char*&nbsp;start&nbsp;=&nbsp;(unsigned&nbsp;char*)pBuffer; unsigned&nbsp;char*&nbsp;end&nbsp;=&nbsp;(unsigned&nbsp;char*)pBuffer&nbsp;+&nbsp;size; while&nbsp;(start&nbsp;&lt;&nbsp;end) { if&nbsp;(*start&nbsp;&lt;&nbsp;0x80)&nbsp;//&nbsp;(10000000):&nbsp;值小于0x80的为ASCII字符&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { start++; } else&nbsp;if&nbsp;(*start&nbsp;&lt;&nbsp;(0xC0))&nbsp;//&nbsp;(11000000):&nbsp;值介于0x80与0xC0之间的为无效UTF-8字符&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { bIsUTF8&nbsp;=&nbsp;false; break; } else&nbsp;if&nbsp;(*start&nbsp;&lt;&nbsp;(0xE0))&nbsp;//&nbsp;(11100000):&nbsp;此范围内为2字节UTF-8字符&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { if&nbsp;(start&nbsp;&gt;=&nbsp;end&nbsp;-&nbsp;1) break; if&nbsp;((start[1]&nbsp;&amp;&nbsp;(0xC0))&nbsp;!=&nbsp;0x80) { bIsUTF8&nbsp;=&nbsp;false; break; } start&nbsp;+=&nbsp;2; } else&nbsp;if&nbsp;(*start&nbsp;&lt;&nbsp;(0xF0))&nbsp;//&nbsp;(11110000):&nbsp;此范围内为3字节UTF-8字符 { if&nbsp;(start&nbsp;&gt;=&nbsp;end&nbsp;-&nbsp;2) break; if&nbsp;((start[1]&nbsp;&amp;&nbsp;(0xC0))&nbsp;!=&nbsp;0x80&nbsp;||&nbsp;(start[2]&nbsp;&amp;&nbsp;(0xC0))&nbsp;!=&nbsp;0x80) { bIsUTF8&nbsp;=&nbsp;false; break; } start&nbsp;+=&nbsp;3; } else { bIsUTF8&nbsp;=&nbsp;false; break; } } return&nbsp;bIsUTF8; } /*! *&nbsp;检查字符串是不是UTF-8编码 * *&nbsp;\param&nbsp;str&nbsp;缓冲区 *&nbsp;\return&nbsp;如果是返回true,否则返回false。 *&nbsp; *&nbsp;\note&nbsp;返回结果并不一定完全正确,仅作为一个参考用途。 */ static&nbsp;bool&nbsp;IsUTF8(const&nbsp;std::string&nbsp;&amp;str) { return&nbsp;IsUTF8(str.c_str(),&nbsp;str.size()); } } //为了方便方便使用定义的宏 #define&nbsp;ANSI_TO_WCHAR(str)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ZEncode::A2W(str,&nbsp;CP_ACP)) #define&nbsp;ANSI_TO_UTF8(str)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ZEncode::A2A(str,&nbsp;CP_ACP,&nbsp;CP_UTF8)) #define&nbsp;UTF8_TO_ANSI(str)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ZEncode::A2A(str,&nbsp;CP_UTF8,&nbsp;CP_ACP)) #define&nbsp;UTF8_TO_WCHAR(str)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ZEncode::A2W(str,&nbsp;CP_UTF8)) #define&nbsp;WCHAR_TO_ANSI(str)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ZEncode::W2A(str,&nbsp;CP_ACP)) #define&nbsp;WCHAR_TO_UTF8(str)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ZEncode::W2A(str,&nbsp;CP_UTF8))</pre><p style="white-space: normal;">&nbsp;</p><p style="white-space: normal; text-indent: 2em;">&nbsp;测试用例(备注:Windows中文版环境[utf-8],Visual Studio默认文件编码[utf-8]):</p><pre class="brush:cpp;toolbar:false">/*****&nbsp;ZEncode&nbsp;*****/ namespace&nbsp;ZEncodeTest { TEST(ZEncode,&nbsp;ansi_to_wchar_to_ansi) { std::string&nbsp;strANSI(&quot;中华人民共和国&quot;); std::wstring&nbsp;strWChar&nbsp;=&nbsp;ANSI_TO_WCHAR(strANSI); EXPECT_STREQ(strWChar.c_str(),&nbsp;L&quot;中华人民共和国&quot;); EXPECT_STREQ(WCHAR_TO_ANSI(strWChar).c_str(),&nbsp;&quot;中华人民共和国&quot;); } TEST(ZEncode,&nbsp;ansi_to_utf8_to_wchar) { std::string&nbsp;strANSI(&quot;中华人民共和国&quot;); std::string&nbsp;strUTF8&nbsp;=&nbsp;ANSI_TO_UTF8(strANSI); EXPECT_FALSE(ZEncode::IsUTF8(strANSI)); EXPECT_TRUE(ZEncode::IsUTF8(strUTF8)); EXPECT_STREQ(UTF8_TO_WCHAR(strUTF8).c_str(),&nbsp;L&quot;中华人民共和国&quot;); } TEST(ZEncode,&nbsp;ansi_to_utf8_to_ansi) { std::string&nbsp;strANSI(&quot;中华人民共和国&quot;); std::string&nbsp;strUTF8&nbsp;=&nbsp;ANSI_TO_UTF8(strANSI); EXPECT_FALSE(ZEncode::IsUTF8(strANSI)); EXPECT_TRUE(ZEncode::IsUTF8(strUTF8)); EXPECT_STREQ(UTF8_TO_ANSI(strUTF8).c_str(),&nbsp;strANSI.c_str()); } TEST(ZEncode,&nbsp;wchar_to_utf8_to_wchar) { std::wstring&nbsp;strWChar(L&quot;中华人民共和国&quot;); std::string&nbsp;strUTF8&nbsp;=&nbsp;WCHAR_TO_UTF8(strWChar); EXPECT_TRUE(ZEncode::IsUTF8(strUTF8)); EXPECT_STREQ(UTF8_TO_WCHAR(strUTF8).c_str(),&nbsp;strWChar.c_str()); } }</pre><p style="white-space: normal;"><br/></p><p style="white-space: normal; text-indent: 2em;">&nbsp; 其它:在C++11中,如果希望初始化的字符串编码为utf-8,只需要在字符前面新增u8即可,如下:<br/></p><pre class="brush:cpp;toolbar:false">std::string&nbsp;s1&nbsp;=&nbsp;&quot;中华人民共和国&quot;;&nbsp;&nbsp;//取决于文件编码 std::string&nbsp;s2&nbsp;=&nbsp;u8&quot;中华人民共和国&quot;;&nbsp;&nbsp;//utf-8编码</pre>Sun, 05 Jul 2020 22:43:25 +0800他小的有http://www.suchone.com/post/49.html<p>&nbsp; 通过Jenkins上的Python插件执行Python脚本时可通过环境变量的方式获取WORKSPACE,JOB_NAME的方法示例:</p><pre class="brush:python;toolbar:false">import&nbsp;os workspace=os.environ[&#39;WORKSPACE&#39;] jobName=os.environ[&#39;JOB_NAME&#39;] print&nbsp;workspace print&nbsp;jobName</pre>Sun, 05 Jul 2020 10:47:50 +0800他小的有http://www.suchone.com/post/48.html<p style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow-x: auto; overflow-wrap: break-word; white-space: normal; background-color: rgb(255, 255, 255); text-indent: 2em;">在自动集成和发布中(如果Jenkins),经常需要命令行的形式来启动Visual Studio来编译项目,可以使用devenv来启动Visual Studio编译项目工和,如下:</p><pre class="brush:bash;toolbar:false">devenv&nbsp;&quot;%WORKSPACE%\Demo.sln&quot;&nbsp;/build&nbsp;Debug&nbsp;/project&nbsp;&quot;Project1\Project1.vcxproj&quot;&nbsp;/projectconfig&nbsp;Debug devenv&nbsp;&quot;%WORKSPACE%\Demo.sln&quot;&nbsp;/build&nbsp;Release&nbsp;/project&nbsp;&quot;Project1\Project1.vcxproj&quot;&nbsp;/projectconfig&nbsp;Release</pre>Fri, 03 Jul 2020 23:28:41 +0800他小的有http://www.suchone.com/post/45.html<p>&nbsp;&nbsp;&nbsp;&nbsp;从nuget导入包到程序中时,可以正常包含头文件,也可以正常使用函数和编译,但是在IDE中显示无法找到头文件和无法跳转到函数,提示函数未定义,如下图所示:</p><p><img src="http://www.suchone.com/zb_users/upload/2019/03/201903271553666168663083.png" title="正在上传..." alt="image.png"/></p><p><strong>解决方案:关闭项目,删除*.VC.db文件,重新打开项目即可。</strong></p><p><img src="http://www.suchone.com/zb_users/upload/2019/03/201903271553666272878820.png" title="正在上传..." alt="image.png"/></p>Wed, 27 Mar 2019 13:53:45 +0800他小的有http://www.suchone.com/post/44.html<p style="text-indent: 2em;">场景:在Nuget服务器上发布相同的yabo亚搏手机最新版app的包,在客户端Nuget获取的包不是服务器最新版本时,可通过清除本地缓存再重新拉取包可解决这个问题。</p><p style="text-indent: 2em;">解决方案:打开Nuget控制台,执行清除本地缓存<br/></p><p style="text-indent: 2em;"><span style="color: rgb(255, 0, 0);">注意事项:需要先下载nuget.exe,并添加到环境变量(在控制台输入nuget命令有对应的信息)</span></p><pre class="brush:as3;toolbar:false">nuget&nbsp;locals&nbsp;all&nbsp;-clear</pre><p style="text-indent: 2em;"><br/></p><p style="text-indent: 2em;">操作步骤:Tools -&gt; NuGet Package Manager -&gt; Package Manager Colsole</p><p><img src="http://www.suchone.com/zb_users/upload/2020/07/202007051593963875681437.png" title="正在上传..." alt="image.png"/></p><p><br/></p><p style="text-indent: 2em;">输入上面的命令回车即可:</p><p><img src="http://www.suchone.com/zb_users/upload/2020/07/202007051593964074653843.png" title="正在上传..." alt="image.png"/></p><p><br/></p><p style="text-indent: 2em;">此时再拉取对应的包即可。</p>Sat, 09 Mar 2019 23:51:28 +0800他小的有http://www.suchone.com/post/43.html<p>&nbsp;&nbsp;&nbsp;&nbsp;<br/></p><pre class="brush:cpp;toolbar:false">#include&nbsp;&lt;string&gt; #include&nbsp;&lt;vector&gt; /** &nbsp;*&nbsp;格式化字符串 &nbsp;*&nbsp; &nbsp;*&nbsp;\param&nbsp;pszFmt&nbsp;格式描述 &nbsp;*&nbsp;\param&nbsp;...&nbsp;不定参数 &nbsp;*&nbsp;\return&nbsp;格式化的结果字符串 &nbsp;*/ std::string&nbsp;format(const&nbsp;char&nbsp;*pszFmt,&nbsp;...) { std::string&nbsp;str; va_list&nbsp;args; va_start(args,&nbsp;pszFmt); { int&nbsp;nLength&nbsp;=&nbsp;_vscprintf(pszFmt,&nbsp;args); nLength&nbsp;+=&nbsp;1;&nbsp;&nbsp;//上面返回的长度是包含\0,这里加上 std::vector&lt;char&gt;&nbsp;chars(nLength); _vsnprintf(chars.data(),&nbsp;nLength,&nbsp;pszFmt,&nbsp;args); str.assign(chars.data()); } va_end(args); return&nbsp;str; } //使用示例: char&nbsp;c&nbsp;=&nbsp;&#39;A&#39;; std::string&nbsp;str&nbsp;=&nbsp;format(&quot;c=%c&quot;,&nbsp;c);&nbsp;&nbsp;//&nbsp;c=A int&nbsp;i&nbsp;=&nbsp;10; str&nbsp;=&nbsp;format(&quot;i=%c&quot;,&nbsp;i);&nbsp;&nbsp;//&nbsp;i=10 double&nbsp;d&nbsp;=&nbsp;1.5; str&nbsp;=&nbsp;format(&quot;d=%f&quot;,&nbsp;d);&nbsp;&nbsp;//&nbsp;d&nbsp;=&nbsp;1.500000 std::string&nbsp;strName&nbsp;=&nbsp;(&quot;txdy&quot;); str&nbsp;=&nbsp;format(&quot;I&nbsp;am&nbsp;%s&quot;,&nbsp;strName.c_str());&nbsp;&nbsp;//&nbsp;I&nbsp;am&nbsp;txdy</pre><p>&nbsp;&nbsp;&nbsp;&nbsp;这样,就可以很方便的格式化字符串了,程序中使用字符串是最常见的操作了,自己也可以封装一个CString类将其归类起来,方便以后的项目中使用。</p>Wed, 16 Aug 2017 19:53:28 +0800