Skip to content

Commit 17081c5

Browse files
committed
deploy: f6935e6
1 parent 0309aec commit 17081c5

File tree

4 files changed

+82
-12
lines changed

4 files changed

+82
-12
lines changed

cpp_tricks/index.html

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@
436436
<ul class="nav flex-column">
437437
</ul>
438438
</li>
439-
<li class="nav-item" data-bs-level="2"><a href="#locale-utf8_1" class="nav-link">设置 locale 为 .utf8 解决编码问题</a>
439+
<li class="nav-item" data-bs-level="2"><a href="#locale-utf8-windows" class="nav-link">设置 locale 为 .utf8 解决 Windows 编码难问题</a>
440440
<ul class="nav flex-column">
441441
</ul>
442442
</li>
@@ -536,7 +536,7 @@ <h1 id="c">应知应会 C++ 小技巧</h1>
536536
<li><a href="#adl">ADL 机制实现静态多态</a></li>
537537
<li><a href="#shared_from_this">shared_from_this</a></li>
538538
<li><a href="#requires">requires 语法检测是否存在指定成员函数</a></li>
539-
<li><a href="#locale-utf8_1">设置 locale 为 .utf8 解决编码问题</a></li>
539+
<li><a href="#locale-utf8-windows">设置 locale 为 .utf8 解决 Windows 编码难问题</a></li>
540540
<li><a href="#this_1">成员函数针对 this 的移动重载</a></li>
541541
<li><a href="#bit-field">位域(bit-field)</a></li>
542542
<li><a href="#vector-unordered_map-lru-cache">vector + unordered_map = LRU cache</a></li>
@@ -787,7 +787,7 @@ <h2 id="_7">继承构造函数</h2>
787787

788788
Child child(23, &quot;peng&quot;); // 错误!Child 没有构造函数!
789789
</code></pre>
790-
<p>可以在子类里面写 <code>using 父类::父类</code>,就能自动继承父类所有的构造函数了。</p>
790+
<p>C++11 中可以在子类里面写 <code>using 父类::父类</code>,就能自动继承父类所有的构造函数了。</p>
791791
<pre><code class="language-cpp">struct Parent {
792792
Parent(int age, const char *name) { ... }
793793
void parent_func() { ... }
@@ -2030,7 +2030,13 @@ <h2 id="adl">ADL 机制实现静态多态</h2>
20302030
<p>TODO</p>
20312031
<h2 id="shared_from_this">shared_from_this</h2>
20322032
<h2 id="requires">requires 语法检测是否存在指定成员函数</h2>
2033-
<h2 id="locale-utf8_1">设置 locale 为 .utf8 解决编码问题</h2>
2033+
<h2 id="locale-utf8-windows">设置 locale 为 .utf8 解决 Windows 编码难问题</h2>
2034+
<pre><code class="language-cpp">system(&quot;chcp 65001&quot;);
2035+
setlocale(&quot;LC_ALL&quot;, &quot;.utf-8&quot;);
2036+
</code></pre>
2037+
<blockquote>
2038+
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 详见 <a href="../unicode/">Unicode 专题章节</a></p>
2039+
</blockquote>
20342040
<h2 id="this_1">成员函数针对 this 的移动重载</h2>
20352041
<h2 id="bit-field">位域(bit-field)</h2>
20362042
<p>在互联网编程和各种与硬盘、序列化打交道的场景中,常常需要按位拆分单个字节。</p>
@@ -2057,7 +2063,36 @@ <h2 id="lambda-unique_ptr-function">Lambda 捕获 unique_ptr 导致 function 报
20572063
<h2 id="_20">多线程通信应基于队列,而不是共享全局变量</h2>
20582064
<h2 id="raii-finally">RAII 的 finally 帮手类</h2>
20592065
<h2 id="swap-mutex">swap 缩小 mutex 区间代价</h2>
2060-
<h2 id="namespace">namespace 别名</h2></div>
2066+
<h2 id="namespace">namespace 别名</h2>
2067+
<p>有些嵌套很深的名字空间每次都要复读非常啰嗦。</p>
2068+
<pre><code class="language-cpp">#include &lt;filesystem&gt;
2069+
2070+
int main() {
2071+
std::filesystem::path p = &quot;/var/www/html&quot;;
2072+
...
2073+
}
2074+
</code></pre>
2075+
<p>如果 <code>using namespace</code> 的话,又觉得污染全局名字空间了。</p>
2076+
<pre><code class="language-cpp">#include &lt;filesystem&gt;
2077+
2078+
using namespace std::filesystem;
2079+
2080+
int main() {
2081+
std::filesystem::path p = &quot;/var/www/html&quot;;
2082+
...
2083+
}
2084+
</code></pre>
2085+
<p>可以用 C++11 的 <code>namespace =</code> 语法,给名字空间取个别名。</p>
2086+
<pre><code class="language-cpp">#include &lt;filesystem&gt;
2087+
2088+
namespace fs = std::filesystem;
2089+
2090+
int main() {
2091+
fs::path p = &quot;/var/www/html&quot;;
2092+
...
2093+
}
2094+
</code></pre>
2095+
<p>这样以后就可以 <code>fs</code> 这个简称访问了。</p></div>
20612096
</div>
20622097
</div>
20632098

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ <h2 id="_1">前言</h2>
292292
<blockquote>
293293
<p><img src="./img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 本书还在持续更新中……要追番的话,可以在 <a href="https://github.com/parallel101/cppguidebook">GitHub</a> 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</p>
294294
</blockquote>
295-
<p>更新时间:2024年10月25日 12:47:54 (UTC+08:00)</p>
295+
<p>更新时间:2024年10月25日 12:54:18 (UTC+08:00)</p>
296296
<p><a href="https://parallel101.github.io/cppguidebook">在 GitHub Pages 浏览本书</a> | <a href="https://142857.red/book">在小彭老师自己维护的镜像上浏览本书</a></p>
297297
<h2 id="_2">格式约定</h2>
298298
<blockquote>

print_page/index.html

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ <h2 id="index-_1">前言</h2>
421421
<blockquote>
422422
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 本书还在持续更新中……要追番的话,可以在 <a href="https://github.com/parallel101/cppguidebook">GitHub</a> 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一封电子邮件,提醒你小彭老师更新了。</p>
423423
</blockquote>
424-
<p>更新时间:2024年10月25日 12:47:54 (UTC+08:00)</p>
424+
<p>更新时间:2024年10月25日 12:54:18 (UTC+08:00)</p>
425425
<p><a href="https://parallel101.github.io/cppguidebook">在 GitHub Pages 浏览本书</a> | <a href="https://142857.red/book">在小彭老师自己维护的镜像上浏览本书</a></p>
426426
<h2 id="index-_2">格式约定</h2>
427427
<blockquote>
@@ -1130,7 +1130,7 @@ <h2 id="symbols-linkage">符号的链接类型 (linkage)</h2>
11301130
<li><a href="#cpp_tricks-adl">ADL 机制实现静态多态</a></li>
11311131
<li><a href="#cpp_tricks-shared_from_this">shared_from_this</a></li>
11321132
<li><a href="#cpp_tricks-requires">requires 语法检测是否存在指定成员函数</a></li>
1133-
<li><a href="#cpp_tricks-locale-utf8_1">设置 locale 为 .utf8 解决编码问题</a></li>
1133+
<li><a href="#cpp_tricks-locale-utf8-windows">设置 locale 为 .utf8 解决 Windows 编码难问题</a></li>
11341134
<li><a href="#cpp_tricks-this_1">成员函数针对 this 的移动重载</a></li>
11351135
<li><a href="#cpp_tricks-bit-field">位域(bit-field)</a></li>
11361136
<li><a href="#cpp_tricks-vector-unordered_map-lru-cache">vector + unordered_map = LRU cache</a></li>
@@ -1381,7 +1381,7 @@ <h2 id="cpp_tricks-_7">继承构造函数</h2>
13811381

13821382
Child child(23, &quot;peng&quot;); // 错误!Child 没有构造函数!
13831383
</code></pre>
1384-
<p>可以在子类里面写 <code>using 父类::父类</code>,就能自动继承父类所有的构造函数了。</p>
1384+
<p>C++11 中可以在子类里面写 <code>using 父类::父类</code>,就能自动继承父类所有的构造函数了。</p>
13851385
<pre><code class="language-cpp">struct Parent {
13861386
Parent(int age, const char *name) { ... }
13871387
void parent_func() { ... }
@@ -2624,7 +2624,13 @@ <h2 id="cpp_tricks-adl">ADL 机制实现静态多态</h2>
26242624
<p>TODO</p>
26252625
<h2 id="cpp_tricks-shared_from_this">shared_from_this</h2>
26262626
<h2 id="cpp_tricks-requires">requires 语法检测是否存在指定成员函数</h2>
2627-
<h2 id="cpp_tricks-locale-utf8_1">设置 locale 为 .utf8 解决编码问题</h2>
2627+
<h2 id="cpp_tricks-locale-utf8-windows">设置 locale 为 .utf8 解决 Windows 编码难问题</h2>
2628+
<pre><code class="language-cpp">system(&quot;chcp 65001&quot;);
2629+
setlocale(&quot;LC_ALL&quot;, &quot;.utf-8&quot;);
2630+
</code></pre>
2631+
<blockquote>
2632+
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 详见 <a href="#unicode">Unicode 专题章节</a>。</p>
2633+
</blockquote>
26282634
<h2 id="cpp_tricks-this_1">成员函数针对 this 的移动重载</h2>
26292635
<h2 id="cpp_tricks-bit-field">位域(bit-field)</h2>
26302636
<p>在互联网编程和各种与硬盘、序列化打交道的场景中,常常需要按位拆分单个字节。</p>
@@ -2651,7 +2657,36 @@ <h2 id="cpp_tricks-lambda-unique_ptr-function">Lambda 捕获 unique_ptr 导致 f
26512657
<h2 id="cpp_tricks-_20">多线程通信应基于队列,而不是共享全局变量</h2>
26522658
<h2 id="cpp_tricks-raii-finally">RAII 的 finally 帮手类</h2>
26532659
<h2 id="cpp_tricks-swap-mutex">swap 缩小 mutex 区间代价</h2>
2654-
<h2 id="cpp_tricks-namespace">namespace 别名</h2></section><section class="print-page" id="lambda"><h1 id="lambda-_1">小彭老师带你学函数式编程</h1>
2660+
<h2 id="cpp_tricks-namespace">namespace 别名</h2>
2661+
<p>有些嵌套很深的名字空间每次都要复读非常啰嗦。</p>
2662+
<pre><code class="language-cpp">#include &lt;filesystem&gt;
2663+
2664+
int main() {
2665+
std::filesystem::path p = &quot;/var/www/html&quot;;
2666+
...
2667+
}
2668+
</code></pre>
2669+
<p>如果 <code>using namespace</code> 的话,又觉得污染全局名字空间了。</p>
2670+
<pre><code class="language-cpp">#include &lt;filesystem&gt;
2671+
2672+
using namespace std::filesystem;
2673+
2674+
int main() {
2675+
std::filesystem::path p = &quot;/var/www/html&quot;;
2676+
...
2677+
}
2678+
</code></pre>
2679+
<p>可以用 C++11 的 <code>namespace =</code> 语法,给名字空间取个别名。</p>
2680+
<pre><code class="language-cpp">#include &lt;filesystem&gt;
2681+
2682+
namespace fs = std::filesystem;
2683+
2684+
int main() {
2685+
fs::path p = &quot;/var/www/html&quot;;
2686+
...
2687+
}
2688+
</code></pre>
2689+
<p>这样以后就可以 <code>fs</code> 这个简称访问了。</p></section><section class="print-page" id="lambda"><h1 id="lambda-_1">小彭老师带你学函数式编程</h1>
26552690
<div class="toc">
26562691
<ul>
26572692
<li><a href="#lambda-_1">小彭老师带你学函数式编程</a><ul>

search/search_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)