diff options
author | 2024-02-23 18:31:34 +0800 | |
---|---|---|
committer | 2024-02-25 13:02:58 +0800 | |
commit | 81248a94826e3ecc05cd6fdd7126078f3f2fc06b (patch) | |
tree | 0dd2454459dceb2bad5ec6b093bbbfdb50214db5 | |
parent | 492fc3361b00869f206ad2499611a52a98947ef4 (diff) | |
download | myweb-81248a94826e3ecc05cd6fdd7126078f3f2fc06b.tar.gz myweb-81248a94826e3ecc05cd6fdd7126078f3f2fc06b.zip |
Add registration number, check highlight bug, fix bugs.
- accroding to the rules of MIIT, every website should show its
registration number on the front page.
- There is a conflict in principle between the export of myhighlight
and typora:
- myhighlight set line number while loading the body of html, but
use selected style after the html is totally loaded.
- the way to judge if html is from typora is to judge the class of
its body, but this needs to be after the load of html
- So, if we check the class of body at the start of myhighlight, we
have to delay myhighlight after the load, which causes the load of
style wrong. We have to give up to combine them.
- Fix content bugs in vim, ohos_compile, and so on.
29 files changed, 3337 insertions, 3076 deletions
diff --git a/code/cpppp.html b/code/cpppp.html index f4f4c9d..ee44972 100644 --- a/code/cpppp.html +++ b/code/cpppp.html | |||
@@ -1,68 +1,1120 @@ | |||
1 | <!doctype html> | 1 | <!DOCTYPE html> |
2 | <html> | 2 | <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> |
3 | |||
3 | <head> | 4 | <head> |
4 | <meta charset='UTF-8'> | 5 | <meta charset="utf-8" /> |
5 | <meta name='viewport' content='width=device-width initial-scale=1'> | 6 | <meta name="generator" content="pandoc" /> |
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | ||
6 | <title>cpppp快速基础</title> | 8 | <title>cpppp快速基础</title> |
7 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/Newsprint.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script><script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script>\n<script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
8 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
9 | </head> | 12 | </head> |
10 | 13 | ||
11 | <body class='typora-export os-windows'> | 14 | <body> |
12 | <div class='typora-export-content'> | 15 | <div class="pandoc"> |
13 | <div id='write' class=''> | 16 | <div class="main"> |
14 | <p class="title">C++ Primer Plus<br>前八章基础快速</p> | 17 | <p class="title">C++ Primer Plus快速基础</p> |
15 | <div class='md-toc' mdtype='toc'><p class="md-toc-content" role="list"><span role="listitem" class="md-toc-item md-toc-h1" data-ref="n2"><a class="md-toc-inner" href="#第二章">第二章</a></span><span role="listitem" class="md-toc-item md-toc-h1" data-ref="n14"><a class="md-toc-inner" href="#第三章">第三章</a></span><span role="listitem" class="md-toc-item md-toc-h1" data-ref="n35"><a class="md-toc-inner" href="#第四章">第四章</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n36"><a class="md-toc-inner" href="#数组">数组</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n45"><a class="md-toc-inner" href="#字符串">字符串</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n67"><a class="md-toc-inner" href="#结构体">结构体</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n88"><a class="md-toc-inner" href="#共用体">共用体</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n94"><a class="md-toc-inner" href="#枚举">枚举</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n96"><a class="md-toc-inner" href="#指针">指针</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n102"><a class="md-toc-inner" href="#指针数组与指针算术">指针、数组与指针算术</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n124"><a class="md-toc-inner" href="#变量存储方式">变量存储方式</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n137"><a class="md-toc-inner" href="#数组替代">数组替代</a></span><span role="listitem" class="md-toc-item md-toc-h1" data-ref="n152"><a class="md-toc-inner" href="#第五章">第五章</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n153"><a class="md-toc-inner" href="#递增递减运算符">递增递减运算符</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n171"><a class="md-toc-inner" href="#指针与递增递减">指针与递增递减</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n176"><a class="md-toc-inner" href="#逗号运算符">逗号运算符</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n181"><a class="md-toc-inner" href="#循环">循环</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n190"><a class="md-toc-inner" href="#循环与文本输入">循环与文本输入</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n196"><a class="md-toc-inner" href="#文件尾eof)条件">文件尾(EOF)条件</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n197"><a class="md-toc-inner" href="#重要性">重要性</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n229"><a class="md-toc-inner" href="#实现">实现</a></span><span role="listitem" class="md-toc-item md-toc-h1" data-ref="n231"><a class="md-toc-inner" href="#第六章">第六章</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n232"><a class="md-toc-inner" href="#逻辑运算符相关">逻辑运算符相关</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n256"><a class="md-toc-inner" href="#字符函数库">字符函数库</a></span><span role="listitem" class="md-toc-item md-toc-h1" data-ref="n259"><a class="md-toc-inner" href="#第七章">第七章</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n260"><a class="md-toc-inner" href="#基础知识">基础知识</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n274"><a class="md-toc-inner" href="#函数与数组">函数与数组</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n280"><a class="md-toc-inner" href="#使用数组区间的函数">使用数组区间的函数</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n283"><a class="md-toc-inner" href="#指针与-const">指针与 const</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n284"><a class="md-toc-inner" href="#将-const-用于指针">将 const 用于指针</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n297"><a class="md-toc-inner" href="#二维数组作参数">二维数组作参数</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n301"><a class="md-toc-inner" href="#返回-c-风格字符串">返回 C 风格字符串</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n304"><a class="md-toc-inner" href="#函数指针">函数指针</a></span><span role="listitem" class="md-toc-item md-toc-h1" data-ref="n331"><a class="md-toc-inner" href="#第八章">第八章</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n332"><a class="md-toc-inner" href="#内联函数">内联函数</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n352"><a class="md-toc-inner" href="#内联的原始实现c-中的define">内联的原始实现:C 中的#define</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n358"><a class="md-toc-inner" href="#引用变量">引用变量</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n359"><a class="md-toc-inner" href="#引用变量是什么能吃吗">引用变量是什么?能吃吗?</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n371"><a class="md-toc-inner" href="#引用变量作函数参数">引用变量作函数参数</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n373"><a class="md-toc-inner" href="#c-风格字符串作-string-对象引用参数">C-风格字符串作 string 对象引用参数</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n378"><a class="md-toc-inner" href="#对象继承和引用">对象、继承和引用</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n381"><a class="md-toc-inner" href="#何时使用引用">何时使用引用</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n409"><a class="md-toc-inner" href="#函数多态">函数多态</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n416"><a class="md-toc-inner" href="#默认参数">默认参数</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n420"><a class="md-toc-inner" href="#函数重载">函数重载</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n426"><a class="md-toc-inner" href="#函数模板">函数模板</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n434"><a class="md-toc-inner" href="#模板重载">模板重载</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n437"><a class="md-toc-inner" href="#模板的局限性">模板的局限性</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n439"><a class="md-toc-inner" href="#具体化与实例化">具体化与实例化</a></span><span role="listitem" class="md-toc-item md-toc-h3" data-ref="n441"><a class="md-toc-inner" href="#编译器选择哪个函数版本">编译器选择哪个函数版本</a></span></p></div><h1 id='第二章'><span>第二章</span></h1><ul><li><p><span>在 C++中,</span><mjx-container class="MathJax" jax="SVG" style="position: relative;"><svg xmlns="http://www.w3.org/2000/svg" width="5.321ex" height="1.52ex" role="img" focusable="false" viewBox="0 -661 2352 672" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" style="vertical-align: -0.025ex;"><defs><path id="MJX-6-TEX-I-1D45A" d="M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z"></path><path id="MJX-6-TEX-I-1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"></path><path id="MJX-6-TEX-I-1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path id="MJX-6-TEX-I-1D45B" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><use data-c="1D45A" xlink:href="#MJX-6-TEX-I-1D45A"></use></g><g data-mml-node="mi" transform="translate(878,0)"><use data-c="1D44E" xlink:href="#MJX-6-TEX-I-1D44E"></use></g><g data-mml-node="mi" transform="translate(1407,0)"><use data-c="1D456" xlink:href="#MJX-6-TEX-I-1D456"></use></g><g data-mml-node="mi" transform="translate(1752,0)"><use data-c="1D45B" xlink:href="#MJX-6-TEX-I-1D45B"></use></g></g></g></svg><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>m</mi><mi>a</mi><mi>i</mi><mi>n</mi></math></mjx-assistive-mml></mjx-container><script type="math/tex">main</script><span>函数括号中使用</span><code>void</code><span>关键字表明拒绝任何参数,而空括号表示对是否接受参数保持沉默。</span></p></li><li><p><span>连续赋值将从右向左进行。</span></p></li><li><p><span>输出拼接长字符串可以如下书写:</span></p></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>4</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">//当代码很长而追求风格的时候,这样操作。</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"1234567"</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-operator"><<</span> <span class="cm-string">"7654321"</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 104px;"></div><div class="CodeMirror-gutters" style="height: 104px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><ul><li><p><span>类描述了一种数据类型的全部属性(包括可用其来执行的操作),对象是根据这些描述创建的实体。</span></p></li></ul><h1 id='第三章'><span>第三章</span></h1><ul><li><p><span>数据输入/常数可以以十进制、十六进制、二进制书写。</span></p></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>9</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 18 | <h1 id="第二章">第二章</h1> |
16 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">a</span> <span class="cm-operator">=</span> <span class="cm-number">10</span>, <span class="cm-variable">b</span> <span class="cm-operator">=</span> <span class="cm-number">0xf</span>, <span class="cm-variable">c</span> <span class="cm-operator">=</span> <span class="cm-number">0b10100</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">a</span> <span class="cm-operator"><<</span> <span class="cm-variable">b</span> <span class="cm-operator"><<</span> <span class="cm-variable">c</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 234px;"></div><div class="CodeMirror-gutters" style="height: 234px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><ul><li><p><code>cout</code><span>提供控制符以八进制、十进制与十六进制显示整数。</span></p></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>18</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">chest</span> <span class="cm-operator">=</span> <span class="cm-number">42</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">waist</span> <span class="cm-operator">=</span> <span class="cm-number">42</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">inseam</span> <span class="cm-operator">=</span> <span class="cm-number">42</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Monsieur cuts a striking figure !"</span> <span class="cm-operator"><<</span><span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">//所有设置,在更改之前将会一直延续</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">//默认显示十进制</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"chest = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">chest</span> <span class="cm-operator"><<</span> <span class="cm-string">"(decimal for 42 ) "</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">hex</span>; <span class="cm-comment">// 显示十六进制</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"'waist = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">waist</span> <span class="cm-operator"><<</span><span class="cm-string">"(hexadecimal for 42)"</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">oct</span>; <span class="cm-comment">// 十进制</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"inseam = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">inseam</span> <span class="cm-operator"><<</span>: <span class="cm-string">" (octal for 42 ) "</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span> ;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 468px;"></div><div class="CodeMirror-gutters" style="height: 468px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><ul><li><p><span>通用字符名</span></p></li></ul><blockquote><p><span>ISO 10646,Unicode 与 UTF-8 的那些事</span></p></blockquote><ul><li><p><span>常量定义,建议使用</span><kbd><span>const</span></kbd><span>限定而非</span><kbd><span>#define</span></kbd><span>,且必须在定义时赋值,否则即乱码数字,后续无法修改。</span></p></li><li><p><span>浮点数赋值直接赋,不认识后缀 f</span></p></li><li><p><code>auto</code><span>声明,自动根据初始值类型推断变量类型。</span></p></li></ul><h1 id='第四章'><span>第四章</span></h1><h2 id='数组'><span>数组</span></h2><ul><li><p><span>数组创建,数组大小必须为常量,不能是变量。</span></p><ul><li><p><span>数组是一种复合类型,是依托于其他类型来创建的(C 称之为派生,而 C++对类关系使用派生这一术语)</span></p></li></ul></li><li><p><span>数组初始化,如果在定义时仅对一部分元素初始化,则其他元素将被设置为 0</span></p></li></ul><h2 id='字符串'><span>字符串</span></h2><ul><li><p><span>拼接字符串常量。字符串过长时允许拼接字符串字面值。</span></p><ul><li><p><span>任两个由空白分隔符(空格、</span><code>\t</code><span>、</span><code>\n</code><span>)分割的字符串常量都会被自动拼接为一个。</span></p></li></ul></li><li><p><kbd><span>get</span></kbd><span>与</span><kbd><span>getline</span></kbd><span>,二者使用方式基本相同,只是前者继承 cin 的特性,不会读取换行符后再从字符串中删除,而是把换行符留在输入队列中。</span></p></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>8</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">/*在没有任何参数的情况下</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*cin.get()会读取下一个字符,即使是换行符</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*因此可用以清空*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">cin</span>.<span class="cm-variable">get</span>(<span class="cm-variable">name</span> , <span class="cm-variable">ArSize</span>);<span class="cm-comment">// read first line</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">cin</span>.<span class="cm-variable">get</span>();<span class="cm-comment">// read newline</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">cin</span>.<span class="cm-variable">get</span>(<span class="cm-variable">dessert</span>. <span class="cm-variable">Arsize</span> ) ;<span class="cm-comment">// read second line</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//前两行可以合并为:</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//cin.get(name, ArSize).het()</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 208px;"></div><div class="CodeMirror-gutters" style="height: 208px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><ul><li><p><span>其他类型字符的使用</span></p><ul><li><p><kbd><span>wchar_t</span></kbd></p></li><li><p><kbd><span>char16_t</span></kbd></p></li><li><p><kbd><span>char32_t</span></kbd></p></li></ul></li><li><p><span>C++</span><kbd><span>string</span></kbd><span>提供字符串翻转函数。</span></p></li></ul><h2 id='结构体'><span>结构体</span></h2><ul><li><p><span>结构体初始化</span></p><ul><li><p><span>按声明顺序将列表声明为结构体初始化</span></p></li><li><p><span>指定对应初始化</span></p></li><li><p><span>构造函数初始化</span></p></li></ul></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>27</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 19 | <ul> |
17 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">struct</span> <span class="cm-def">student</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">id</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">string</span> <span class="cm-variable">name</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">short</span> <span class="cm-variable">scores</span>[<span class="cm-number">3</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">void</span> <span class="cm-variable">student</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">id</span>,<span class="cm-variable">string</span> <span class="cm-variable">name</span>,<span class="cm-variable-3">short</span> <span class="cm-variable">scores</span>[])</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">this</span><span class="cm-operator">-></span><span class="cm-variable">id</span><span class="cm-operator">=</span><span class="cm-variable">id</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">this</span><span class="cm-operator">-></span><span class="cm-variable">name</span><span class="cm-operator">=</span><span class="cm-variable">name</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable-3">char</span> <span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">0</span>;<span class="cm-variable">i</span><span class="cm-operator"><</span><span class="cm-number">3</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">this</span><span class="cm-operator">-></span><span class="cm-variable">scores</span>[<span class="cm-variable">i</span>]<span class="cm-operator">=</span><span class="cm-variable">scores</span>[<span class="cm-variable">i</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">};</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 20 | <li>在 C++中,<span |
18 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">student</span> <span class="cm-variable">a</span><span class="cm-operator">=</span>{<span class="cm-number">2021110884</span>,<span class="cm-string">"QJGZ"</span>,<span class="cm-number">150</span>,<span class="cm-number">150</span>,<span class="cm-number">150</span>};</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">strdent</span> <span class="cm-variable">b</span><span class="cm-operator">=</span>{.<span class="cm-variable">id</span><span class="cm-operator">=</span><span class="cm-number">2021110884</span>,.<span class="cm-variable">name</span><span class="cm-operator">=</span><span class="cm-string">"陈一豪"</span>,.<span class="cm-variable">scores</span><span class="cm-operator">=</span>{<span class="cm-number">150</span>,<span class="cm-number">150</span>,<span class="cm-number">150</span>}};</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">student</span> <span class="cm-variable">c</span>(<span class="cm-number">2021110884</span>,<span class="cm-string">"QJGZ"</span>,{<span class="cm-number">150</span>,<span class="cm-number">150</span>,<span class="cm-number">150</span>});</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 21 | class="math inline"><em>m</em><em>a</em><em>i</em><em>n</em></span>函数括号中使用<code>void</code>关键字表明拒绝任何参数,而空括号表示对是否接受参数保持沉默。 |
19 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 702px;"></div><div class="CodeMirror-gutters" style="height: 702px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><blockquote><p><span>注意,前两种方法不能使用在有构造函数的结构体中,否则会报错“指示符不能用于非聚合类型”。</span></p><p><span>对于所有非聚合类型,不能使用初始化列表(即用列表形式初始化,前两种方法是也)。</span></p><p><span>聚合类型定义如下:</span></p><ul><li><p><span>数组</span></p></li><li><p><span>不包含(构造函数、private 和 protect、基类、虚函数)的类、结构体和联合体</span></p></li></ul></blockquote><h2 id='共用体'><span>共用体</span></h2><p><span>举例:一个小商品目录,一些商品 id 为字符串,另一些为数字:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>11</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">union</span> <span class="cm-def">id</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">long</span> <span class="cm-variable">id_num</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">char</span> <span class="cm-variable">id_str</span>[<span class="cm-number">32</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">};</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">struct</span> <span class="cm-def">good</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">char</span> <span class="cm-variable">brand</span>[<span class="cm-number">20</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">type</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">id</span> <span class="cm-variable">id_val</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">};</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 286px;"></div><div class="CodeMirror-gutters" style="height: 286px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>同时,有匿名共用体:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>11</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 22 | </li> |
20 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">struct</span> <span class="cm-def">good</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">char</span> <span class="cm-variable">brand</span>[<span class="cm-number">20</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">type</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">union</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">long</span> <span class="cm-variable">id_num</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">char</span> <span class="cm-variable">id_str</span>[<span class="cm-number">32</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">};</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 286px;"></div><div class="CodeMirror-gutters" style="height: 286px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>匿名共用体没有自己的名称,成员将成为位于同一位置的不同变量,被视为上一级的成员。</span></p><h2 id='枚举'><span>枚举</span></h2><p><strong><span>啥 JB 东西,看不懂!!!</span></strong></p><h2 id='指针'><span>指针</span></h2><ul><li><p><kbd><span>int</span><span>*</span></kbd><span>被理解为一种复合类型而存在,但</span><kbd><span>int</span><span>*</span><span> a, b</span></kbd><span>被解释为一个指针和一个整型</span></p></li></ul><blockquote><p><span>哪个 TM 大聪明的主意?</span></p></blockquote><h3 id='指针数组与指针算术'><span>指针、数组与指针算术</span></h3><p><span>指针与数组基本等价的原因在于指针算数和 C++内部处理方式。</span></p><p><span>算术:</span></p><ul><li><p><span>整型变量递增+1,指针变量递增加的是指向的类型的字节数。</span><strong><span>这同时表明,C++将数组名解释为地址。</span></strong></p></li><li><p><span>可以以相同的形式使用指针与数组名。</span></p><ul><li><p><span>方括号数组表示</span></p></li><li><p><span>加偏移量而后解引用</span></p></li></ul></li><li><p><span>注意:</span></p><ul><li><p><strong><span>数组名直接取地址为整个数组作为内存块的地址,递增时加的是整块大小</span></strong></p></li><li><p><strong><span>数组名本身是首个元素的地址,递增时加的是元素大小</span></strong></p></li><li><p><span>二者初值相同</span></p></li></ul></li></ul><h2 id='变量存储方式'><span>变量存储方式</span></h2><ul><li><p><span>局部存储</span></p></li><li><p><span>静态存储</span></p><ul><li><p><span>定义为全局变量</span></p></li><li><p><span>使用</span><kbd><span>static</span></kbd><span>关键字,如</span><kbd><span>static int c=3; </span></kbd></p></li></ul></li><li><p><span>动态存储</span></p></li></ul><h2 id='数组替代'><span>数组替代</span></h2><ul><li><p><kbd><span>vector</span></kbd></p><ul><li><p><span>分配在自由存储区或堆中。</span></p></li><li><p><span>功能强大,效率略低</span></p></li></ul></li><li><p><kbd><span>array</span></kbd></p><ul><li><p><span>长度固定如数组,和数组一样分配在栈上而非自由存储区,因而效率同于数组,但更方便安全。</span></p></li></ul></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>17</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <array></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 23 | <li>连续赋值将从右向左进行。</li> |
21 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">array</span><span class="cm-operator"><</span><span class="cm-variable-3">int</span>,<span class="cm-number">5</span><span class="cm-operator">></span> <span class="cm-variable">a</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">i</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">0</span>;<span class="cm-variable">i</span><span class="cm-operator"><</span><span class="cm-number">5</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cin</span><span class="cm-operator">>></span><span class="cm-variable">a</span>[<span class="cm-variable">i</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">0</span>;<span class="cm-variable">i</span><span class="cm-operator"><</span><span class="cm-number">5</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-variable">a</span>[<span class="cm-variable">i</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 442px;"></div><div class="CodeMirror-gutters" style="height: 442px; left: 0px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><h1 id='第五章'><span>第五章</span></h1><h2 id='递增递减运算符'><span>递增递减运算符</span></h2><ul><li><p><span>写在后边,则变量先使用,再加/减</span></p></li><li><p><span>写在前边,则变量先加/减,再使用</span></p></li><li><p><span>避免使用不完整的表达式</span></p></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>16</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">//完整的表达式</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">0</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">while</span>(<span class="cm-variable">i</span><span class="cm-operator">++<</span><span class="cm-number">10</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-variable">i</span><span class="cm-operator"><<</span><span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">/*在上例中,先执行判断,而后递增,再输出,因而输出结果为[1,10]</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*这是因为i++<10本身是一个完整表达式</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 24 | <li>输出拼接长字符串可以如下书写:</li> |
22 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">//不完整表达式</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">y</span><span class="cm-operator">=</span>(<span class="cm-number">4</span><span class="cm-operator">+</span><span class="cm-variable">x</span><span class="cm-operator">++</span>)<span class="cm-operator">+</span>(<span class="cm-number">6</span><span class="cm-operator">+</span><span class="cm-variable">x</span><span class="cm-operator">++</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">/*上式中,(4+x++)并不是一个完整表达式,无法保证执行完本处计算后x即刻+1</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*因而整条语句结果并不确定</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 25 | </ul> |
23 | </span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 416px;"></div><div class="CodeMirror-gutters" style="height: 416px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><blockquote><p><span>解释:</span></p><ul><li><p><span>副作用指计算表达式时对某些东西进行了修改</span></p></li><li><p><span>顺序点指程序过程中一个点,在这里将在进入下一步之前对所有副作用进行评估。</span></p></li></ul><p><span>在 C++中,语句的分号是一个顺序点,在下一步之前会把所有副作用造成的修改弄到位。</span> | 26 | <pre><code> //当代码很长而追求风格的时候,这样操作。 |
24 | <span>上例中,前者即有顺序点,执行之前就完成了副作用;后者顺序点在分号,因而副作用结果并不确定。</span></p></blockquote><p><span>本身即为运算表达式,有返回值,返回值即上所谓“使用”。</span></p><h3 id='指针与递增递减'><span>指针与递增递减</span></h3><p><span>递增递减作用不赘。</span></p><p><span>前缀递增递减与解引用运算优先级相同,因而从内向外解释:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">a</span>[<span class="cm-number">2</span>]<span class="cm-operator">=</span>{<span class="cm-number">1</span>,<span class="cm-number">2</span>},<span class="cm-operator">*</span><span class="cm-variable">pt</span><span class="cm-operator">=</span><span class="cm-variable">a</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span><span class="cm-operator"><<*++</span><span class="cm-variable">pt</span><span class="cm-operator"><<*</span>(<span class="cm-operator">++</span><span class="cm-variable">pt</span>)<span class="cm-operator"><<</span><span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">//输出结果,二者相等,即*++pt先执行递增,而后经过顺序点,再解引用,实际为a[1]=2</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 78px;"></div><div class="CodeMirror-gutters" style="height: 78px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><p><span>后缀递增递减优先级高于解引用,因而</span><span>*</span><span>pt++结果与上亦同。</span></p><h2 id='逗号运算符'><span>逗号运算符</span></h2><p><span>逗号运算符允许把两个表达式放一行,表达式的值是后半句的值。</span></p><blockquote><p><span>普通赋值运算式的值为右值。</span></p></blockquote><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>11</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include<iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">a</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">a</span><span class="cm-operator">=</span><span class="cm-number">1</span>,<span class="cm-number">2</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-variable">a</span><span class="cm-operator"><<</span><span class="cm-variable">endl</span>;<span class="cm-comment">//输出1,2不起作用</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">a</span><span class="cm-operator">=</span>(<span class="cm-number">1</span>,<span class="cm-number">2</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-variable">a</span><span class="cm-operator"><<</span><span class="cm-variable">endl</span>;<span class="cm-comment">//输出2</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 286px;"></div><div class="CodeMirror-gutters" style="height: 286px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><h2 id='循环'><span>循环</span></h2><p><kbd><span>for</span></kbd><span>循环与</span><kbd><span>while</span></kbd><span>循环的本质是相同的:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>12</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">for</span>(<span class="cm-variable">init</span><span class="cm-operator">-</span><span class="cm-variable">expression</span>; <span class="cm-variable">test</span><span class="cm-operator">-</span><span class="cm-variable">expression</span>; <span class="cm-variable">update</span><span class="cm-operator">-</span><span class="cm-variable">expression</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">statements</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 27 | cout << "1234567" |
25 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//等价于下述表达</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">init</span><span class="cm-operator">-</span><span class="cm-variable">expression</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">while</span> (<span class="cm-variable">test</span><span class="cm-operator">-</span><span class="cm-variable">expression</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">statements</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">update</span><span class="cm-operator">-</span><span class="cm-variable">expression</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 312px;"></div><div class="CodeMirror-gutters" style="height: 312px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>区别:</span></p><ul><li><p><span>在</span><kbd><span>for</span></kbd><span>循环中省略测试表达式时默认为 true,而</span><kbd><span>while</span></kbd><span>中禁止此种行为</span></p></li><li><p><span>在循环体中有</span><kbd><span>continue</span></kbd><span>语句时,二者表现不再完全等价,稍有不同</span></p></li></ul><h2 id='循环与文本输入'><span>循环与文本输入</span></h2><ul><li><p><span>逐个读取字符需要检查遇到的每个字符包括空格、制表、换行等非显示字符。此时应当使用</span><kbd><span>cin.get()</span></kbd><span>函数。</span></p></li><li><p><span>函数</span><kbd><span>cin.get(ch)</span></kbd><span>读取输入中的下一个字符(包括空格)并赋值给 ch,可以替换</span><kbd><span>cin>>ch</span></kbd><span>。</span></p></li></ul><h2 id='文件尾eof)条件'><span>文件尾(EOF)条件</span></h2><h3 id='重要性'><span>重要性</span></h3><ul><li><p><span>很多操作系统(包括 Unix、Linux 和 Windows 命令提示符模式)都支持重定向,允许用文件替换键盘输入。</span></p></li></ul><blockquote><p><span>例如,假设在 Windows 中有一个名为 gofish.exe 的可执行程序和一个名为 fishtale 的文本文件,则可以在命令提示符模式下输入下面的命令:</span></p><p><span>gofish < fishtale</span></p><p><span>来实现以文本文件代替输入。</span></p></blockquote><ul><li><p><span>很多操作系统都允许通过键盘来模拟文件尾条件。</span></p><ul><li><p><span>在 Unix 中,可以在行首按下 Ctrl+D 来实现;</span></p></li><li><p><span>在 Windows 命令提示符模式下,可以在任意位置放 Ctrl+Z 和 Enter。</span></p></li><li><p><span>有些 C++实现支持类似的行为,即使底层操作系统并不支持。</span></p></li></ul></li></ul><blockquote><p><span>键盘输入的 EOF 概念实际上是命令行环境遗留边倒下来的。</span></p><p><span>然而:</span></p><ul><li><p><span>用于 Mac 的 Symantec C++模拟了 Unix,将 Ctrl+D 视为仿真的 EOF</span></p></li><li><p><span>Metrowerks Codewarrior 能够在 Macintosh 和 Windows 环境下识别 Ctr1+Z</span></p></li><li><p><span>用于 PC 的 Microsoft Visual C++、Borland C++ 5.5 和 GNU C++都能够识别行首的 Ctrl+Z,但用户必须随后按下回车键。</span></p></li></ul><p><span>总之,很多 PC 编程环绕都将 CtrI+Z 视为模拟的 EOF,但具体细节(必须在行首还是可以在任何位置,是否必须按下回车键等)各不相同。</span></p></blockquote><ul><li><p><span>如果编程环境能识别 EOF,则既可以使用重定向文件输入也可以用键盘,岂不美哉?</span></p></li></ul><h3 id='实现'><span>实现</span></h3><p><span>检测到 EOF 后,cin 将两位(</span><kbd><span>eofbit</span></kbd><span>与</span><kbd><span>failbit</span></kbd><span>)均设置为 1。(可通过成员函数</span><kbd><span>bool cin.eof()</span></kbd><span>和</span><kbd><span>bool cin.fail()</span></kbd><span>查看情况,且是在读取之后查看。)</span></p><h1 id='第六章'><span>第六章</span></h1><h2 id='逻辑运算符相关'><span>逻辑运算符相关</span></h2><ul><li><p><span>逻辑与/或的优先级均低于关系运算符</span></p><ul><li><p><span>逻辑与的优先级高于逻辑或</span></p></li></ul></li><li><p><span>逻辑非的优先级高于所有关系运算符和算术运算符,因而要对表达式求反必须括起来。</span></p></li><li><p><span>另一套表示方式</span></p></li></ul><figure><table><thead><tr><th><span>运算符</span></th><th><span>另一种表示</span></th></tr></thead><tbody><tr><td><span>&&</span></td><td><span>and</span></td></tr><tr><td><span>|</span><span>|</span></td><td><span>or</span></td></tr><tr><td><span>!</span></td><td><span>not</span></td></tr></tbody></table></figure><h2 id='字符函数库'><span>字符函数库</span></h2><p><span>cctype(C 语言中的 ctype.h)可以用来确定字符是否为大/小写字母、数字、标点等。其优点在于更简单、更通用(字母、数字之类在不同的编码方式之下不一定都像 ASCII 中一样的连续分布)。包含的函数如下:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>16</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">namespace</span> <span class="cm-def">std</span> {</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isalnum</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isalpha</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isblank</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">iscntrl</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isdigit</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isgraph</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">islower</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isprint</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">ispunct</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isspace</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isupper</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">isxdigit</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">tolower</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-def">toupper</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 416px;"></div><div class="CodeMirror-gutters" style="height: 416px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><h1 id='第七章'><span>第七章</span></h1><h2 id='基础知识'><span>基础知识</span></h2><ul><li><p><span>函数原型:说明函数名、形参类型/名称、返回值类型</span></p><ul><li><p><span>其实就是</span><mjx-container class="MathJax" jax="SVG" style="position: relative;"><svg xmlns="http://www.w3.org/2000/svg" width="7.081ex" height="2.262ex" role="img" focusable="false" viewBox="0 -750 3130 1000" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" style="vertical-align: -0.566ex;"><defs><path id="MJX-7-TEX-I-1D45A" d="M21 287Q22 293 24 303T36 341T56 388T88 425T132 442T175 435T205 417T221 395T229 376L231 369Q231 367 232 367L243 378Q303 442 384 442Q401 442 415 440T441 433T460 423T475 411T485 398T493 385T497 373T500 364T502 357L510 367Q573 442 659 442Q713 442 746 415T780 336Q780 285 742 178T704 50Q705 36 709 31T724 26Q752 26 776 56T815 138Q818 149 821 151T837 153Q857 153 857 145Q857 144 853 130Q845 101 831 73T785 17T716 -10Q669 -10 648 17T627 73Q627 92 663 193T700 345Q700 404 656 404H651Q565 404 506 303L499 291L466 157Q433 26 428 16Q415 -11 385 -11Q372 -11 364 -4T353 8T350 18Q350 29 384 161L420 307Q423 322 423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 181Q151 335 151 342Q154 357 154 369Q154 405 129 405Q107 405 92 377T69 316T57 280Q55 278 41 278H27Q21 284 21 287Z"></path><path id="MJX-7-TEX-I-1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"></path><path id="MJX-7-TEX-I-1D456" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path><path id="MJX-7-TEX-I-1D45B" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path id="MJX-7-TEX-N-28" d="M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z"></path><path id="MJX-7-TEX-N-29" d="M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><use data-c="1D45A" xlink:href="#MJX-7-TEX-I-1D45A"></use></g><g data-mml-node="mi" transform="translate(878,0)"><use data-c="1D44E" xlink:href="#MJX-7-TEX-I-1D44E"></use></g><g data-mml-node="mi" transform="translate(1407,0)"><use data-c="1D456" xlink:href="#MJX-7-TEX-I-1D456"></use></g><g data-mml-node="mi" transform="translate(1752,0)"><use data-c="1D45B" xlink:href="#MJX-7-TEX-I-1D45B"></use></g><g data-mml-node="mo" transform="translate(2352,0)"><use data-c="28" xlink:href="#MJX-7-TEX-N-28"></use></g><g data-mml-node="mo" transform="translate(2741,0)"><use data-c="29" xlink:href="#MJX-7-TEX-N-29"></use></g></g></g></svg><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>m</mi><mi>a</mi><mi>i</mi><mi>n</mi><mo stretchy="false">(</mo><mo stretchy="false">)</mo></math></mjx-assistive-mml></mjx-container><script type="math/tex">main()</script><span>之前的函数声明</span></p></li><li><p><span>函数原型中的函数特征标(参数列表)可以省略标识符(形参名称)而只是指出其类型</span></p></li></ul></li></ul><blockquote><p><sub><span>其实就是那个二锅头,兑的那个白开水</span></sub></p></blockquote><ul><li><p><span>函数定义:函数的本体实现</span></p></li></ul><h2 id='函数与数组'><span>函数与数组</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>6</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//函数定义</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">sum_arr</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">arr</span>[], <span class="cm-variable-3">int</span> <span class="cm-variable">n</span>);<span class="cm-comment">//对数组中元素求和</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 28 | << "7654321" |
26 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//函数调用</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">a</span>[<span class="cm-number">10</span>]<span class="cm-operator">=</span>{<span class="cm-variable">……</span>};<span class="cm-comment">//一堆破数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">sum</span><span class="cm-operator">=</span><span class="cm-variable">sum_arr</span>(<span class="cm-variable">a</span>,<span class="cm-number">10</span>);</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 156px;"></div><div class="CodeMirror-gutters" style="height: 156px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><p><span>以上定义的函数,</span><strong><span>第一个形参是指针而非数组</span></strong><span>,但可以当做数组使用。</span></p><p><strong><span>原因:</span></strong><span>C++与 C 一样,将数组名视为指针,指向第一个元素地址,对应元素大小为单个元素大小,详前。(相比之下,</span><kbd><span>&a</span></kbd><span>虽然也是指向首地址,但大小是整块数组的大小。)因而第一个形参实际是</span><kbd><span>int</span><span>*</span><span> arr</span></kbd><span>,即定义应当为:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">sum_arr</span>(<span class="cm-variable-3">int*</span> <span class="cm-variable">arr</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">n</span>);</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 26px;"></div><div class="CodeMirror-gutters" style="height: 26px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><p><span>这证明两种形参声明同时正确。</span><strong><span>在 C++中,</span><kbd><span>int</span><span>*</span><span> arr</span></kbd><span>与</span><kbd><span>int arr[]</span></kbd><span>当且仅当出现在函数头或函数原型的时候,含义才相同</span></strong><span>。它们都意味着 arr 是一个</span><kbd><span>int</span><span>*</span></kbd><span>。</span></p><h2 id='使用数组区间的函数'><span>使用数组区间的函数</span></h2><blockquote><p><span>屁话一堆,无非就是给定首尾元素的指针为形参,在中间作妖罢了。不说也罢。</span></p></blockquote><h2 id='指针与-const'><span>指针与 const</span></h2><h3 id='将-const-用于指针'><span>将 const 用于指针</span></h3><ul><li><p><span>指针指向</span><mjx-container class="MathJax" jax="SVG" style="position: relative;"><svg xmlns="http://www.w3.org/2000/svg" width="5.312ex" height="1.441ex" role="img" focusable="false" viewBox="0 -626 2348 637" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" style="vertical-align: -0.025ex;"><defs><path id="MJX-8-TEX-I-1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325T330 359T352 380T366 386H367Q367 388 361 392T340 400T306 404Q276 404 249 390Q228 381 206 359Q162 315 142 235T121 119Q121 73 147 50Q169 26 205 26H209Q321 26 394 111Q403 121 406 121Q410 121 419 112T429 98T420 83T391 55T346 25T282 0T202 -11Q127 -11 81 37T34 159Z"></path><path id="MJX-8-TEX-I-1D45C" d="M201 -11Q126 -11 80 38T34 156Q34 221 64 279T146 380Q222 441 301 441Q333 441 341 440Q354 437 367 433T402 417T438 387T464 338T476 268Q476 161 390 75T201 -11ZM121 120Q121 70 147 48T206 26Q250 26 289 58T351 142Q360 163 374 216T388 308Q388 352 370 375Q346 405 306 405Q243 405 195 347Q158 303 140 230T121 120Z"></path><path id="MJX-8-TEX-I-1D45B" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path><path id="MJX-8-TEX-I-1D460" d="M131 289Q131 321 147 354T203 415T300 442Q362 442 390 415T419 355Q419 323 402 308T364 292Q351 292 340 300T328 326Q328 342 337 354T354 372T367 378Q368 378 368 379Q368 382 361 388T336 399T297 405Q249 405 227 379T204 326Q204 301 223 291T278 274T330 259Q396 230 396 163Q396 135 385 107T352 51T289 7T195 -10Q118 -10 86 19T53 87Q53 126 74 143T118 160Q133 160 146 151T160 120Q160 94 142 76T111 58Q109 57 108 57T107 55Q108 52 115 47T146 34T201 27Q237 27 263 38T301 66T318 97T323 122Q323 150 302 164T254 181T195 196T148 231Q131 256 131 289Z"></path><path id="MJX-8-TEX-I-1D461" d="M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><use data-c="1D450" xlink:href="#MJX-8-TEX-I-1D450"></use></g><g data-mml-node="mi" transform="translate(433,0)"><use data-c="1D45C" xlink:href="#MJX-8-TEX-I-1D45C"></use></g><g data-mml-node="mi" transform="translate(918,0)"><use data-c="1D45B" xlink:href="#MJX-8-TEX-I-1D45B"></use></g><g data-mml-node="mi" transform="translate(1518,0)"><use data-c="1D460" xlink:href="#MJX-8-TEX-I-1D460"></use></g><g data-mml-node="mi" transform="translate(1987,0)"><use data-c="1D461" xlink:href="#MJX-8-TEX-I-1D461"></use></g></g></g></svg><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>c</mi><mi>o</mi><mi>n</mi><mi>s</mi><mi>t</mi></math></mjx-assistive-mml></mjx-container><script type="math/tex">const</script><span>常量,防止修改</span></p></li><li><p><span>传参将指针本身声明为常量,防止修改指针指向的位置,但可以修改内容</span></p></li></ul><p><span>优点:</span></p><ul><li><p><span>避免无意见修改数据导致错误</span></p></li><li><p><kbd><span>const</span></kbd><span>可使函数能处理 const 与非 const 实参,否则只能接收后者。</span></p></li></ul><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>12</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//只能防止修改pt指向的值,但pt本身可以改成新地址</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">age</span><span class="cm-operator">=</span><span class="cm-number">39</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">int*</span> <span class="cm-variable">pt</span><span class="cm-operator">=&</span><span class="cm-variable">age</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">sage</span><span class="cm-operator">=</span><span class="cm-number">80</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">pt</span><span class="cm-operator">=&</span><span class="cm-variable">sage</span>;<span class="cm-comment">//是可以的,不会出问题</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 29 | << endl;</code></pre> |
27 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//下面两个是有区别滴,仔细看</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">sloth</span><span class="cm-operator">=</span><span class="cm-number">3</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">int*</span> <span class="cm-variable">ps</span><span class="cm-operator">=&</span><span class="cm-variable">sloth</span>;<span class="cm-comment">//指向const int类型的指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int*</span> <span class="cm-keyword">const</span> <span class="cm-variable">finger</span><span class="cm-operator">=&</span><span class="cm-variable">sloth</span>;<span class="cm-comment">//指向int的const指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//前者如上例,不能修改内容,但能重新指向</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//后者则不能重新指向,但可以修改内容</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 312px;"></div><div class="CodeMirror-gutters" style="height: 312px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><h2 id='二维数组作参数'><span>二维数组作参数</span></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>6</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">sum</span>(<span class="cm-variable-3">int</span> (<span class="cm-operator">*</span><span class="cm-variable">arr</span>)[<span class="cm-number">4</span>], <span class="cm-variable-3">int</span> <span class="cm-variable">size</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//等价于以下</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">aum</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">arr</span>[][<span class="cm-number">4</span>], <span class="cm-variable-3">int</span> <span class="cm-variable">size</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 30 | <ul> |
28 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//不能声明为</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">sum</span>(<span class="cm-variable-3">int</span> <span class="cm-variable-3">*</span><span class="cm-variable">arr</span>[<span class="cm-number">4</span>], <span class="cm-variable-3">int</span> <span class="cm-variable">size</span>);</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 156px;"></div><div class="CodeMirror-gutters" style="height: 156px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><p><strong><span>之所以不能声明为最后一个,是由于第一个形参应当是指向数组的指针,而不是单纯的二重指针。</span></strong><span>上述两个可用原型都指出,第一个形参类型实际上是指向 4 个元素的数组的指针。我之困惑于此也久矣,今乃得闻。</span></p><p><span>基于此,则传参之后仍可以二维数组待之,其原因为</span><kbd><span>arr[i]</span></kbd><span>被解释为</span><kbd><span>*</span><span>(arr+i)</span></kbd><span>,是第 i 个数组,则</span><kbd><span>arr</span>[<span>i</span>][j]</kbd><span>被解释为第 i 个数组的第 j 个元素,即为二维数组。</span></p><h2 id='返回-c-风格字符串'><span>返回 C 风格字符串</span></h2><p><span>听起来很扯淡,对吧?返回值怎么可能是数组类型?内部声明的数组在退出的时候不是就释放了吗?</span></p><p><span>那么,有没有一种可能,我是说可能,内部用</span><kbd><span>new</span></kbd><span>申请一段空间给</span><kbd><span>char</span><span>*</span></kbd><span>,然后写完了返回,在主函数中用完了在</span><kbd><span>delete</span></kbd><span>呢?</span></p><h2 id='函数指针'><span>函数指针</span></h2><p><span>为了实现函数指针,必须要完成:</span></p><ul><li><p><span>获取函数的首地址</span></p><ul><li><p><span>方法很简单,直接使用函数名即可。</span></p></li></ul></li></ul><blockquote><p><span>如</span><kbd><span>think()</span></kbd><span>是一个函数,则</span><kbd><span>think</span></kbd><span>就是该函数地址。要作为参数传递,必须传递函数名。</span><strong><span>要区分传递的是函数名还是函数返回值哦!</span></strong></p></blockquote><ul><li><p><span>声明一个函数指针</span></p><ul><li><p><span>声明一般指针需要说明指向的类型,函数指针也一样。这就是说,声明应指出函数的返回类型及其特征标(参数列表)。</span></p></li></ul></li><li><p><span>使用函数指针来调用函数</span></p></li></ul><p><span>例程如下:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>33</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 31 | <li>类描述了一种数据类型的全部属性(包括可用其来执行的操作),对象是根据这些描述创建的实体。</li> |
29 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">bool</span> <span class="cm-def">hello</span>(<span class="cm-variable">string</span> <span class="cm-variable">name</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Hello, "</span> <span class="cm-operator"><<</span> <span class="cm-variable">name</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-atom">true</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 32 | </ul> |
30 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 函数指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">bool</span> (<span class="cm-operator">*</span><span class="cm-variable">pf</span>)(<span class="cm-variable">string</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 函数参数为string型,返回值bool,指针名称pf。</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 33 | <h1 id="第三章">第三章</h1> |
31 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">/* 上例是将<kbd>(*pf)</kbd>替代了<kbd>pam</kbd>,也就是说</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">* <kbd>(*pf)</kbd>是函数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*从而<kbd>pf</kbd>是函数指针。</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 34 | <ul> |
32 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">/* 为提供正确的运算符优先级,应当用括号将`*`与`pf`括起来</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">* 括号优先级高于`*`,从而:</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">* <kbd>*pf(string)</kbd>意味着<kbd>*pf(string)</kbd>是返回指针的函数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">* <kbd>(*pf)(string)</kbd>意味着<kbd>pf</kbd>是指向函数的指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">*/</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 35 | <li>数据输入/常数可以以十进制、十六进制、二进制书写。</li> |
33 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 赋值</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">29</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">pf</span> <span class="cm-operator">=</span> <span class="cm-variable">hello</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">30</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 36 | </ul> |
34 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 调用</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">pf</span>(<span class="cm-string">"World"</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 858px;"></div><div class="CodeMirror-gutters" style="height: 858px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>我又要骂人了,这什么东西,类型声明这么复杂?不用了不用了,享受不来。</span></p><p><span>没事,C++11 还有个特性叫</span><kbd><span>auto</span></kbd><span>,不是么?</span></p><p><span>上边的例程可以被改写成如下形式:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>17</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 37 | <pre><code>#include <iostream> |
35 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">bool</span> <span class="cm-def">hello</span>(<span class="cm-variable">string</span> <span class="cm-variable">name</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Hello, "</span> <span class="cm-operator"><<</span> <span class="cm-variable">name</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-atom">true</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 38 | using namespace std; |
36 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">//函数指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">auto</span> <span class="cm-variable">pf</span> <span class="cm-operator">=</span> <span class="cm-variable">hello</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 调用</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">pf</span>(<span class="cm-string">"World"</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 442px;"></div><div class="CodeMirror-gutters" style="height: 442px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><del><span>这自动推断类型,多是一件美逝了!</span></del><span>让我们一起说,</span><strong><span>谢谢</span><kbd><span>auto</span></kbd><span>!</span></strong></p><p><span>另外,如果有若干函数返回类型和特征标都相同,都需要调用的话,何不考虑一下函数指针数组呢?更进一步地,为什么不选择创建一个指向整个函数指针数组的指针呢?</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>45</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 39 | |
37 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">// 没错,函数原型可以不写形参名称的</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">// 假设这段代码之外我们有函数的具体定义</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">double</span> <span class="cm-variable-3">*</span><span class="cm-def">f1</span>(<span class="cm-variable-3">int</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">double</span> <span class="cm-variable-3">*</span><span class="cm-def">f2</span>(<span class="cm-variable-3">int</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">double</span> <span class="cm-variable-3">*</span><span class="cm-def">f3</span>(<span class="cm-variable-3">int</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 40 | int main() |
38 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 定义一个指向函数的指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">const</span> <span class="cm-variable-3">double</span> <span class="cm-variable-3">*</span>(<span class="cm-operator">*</span><span class="cm-variable">p</span>[<span class="cm-number">3</span>])(<span class="cm-variable-3">int</span>) <span class="cm-operator">=</span> {<span class="cm-variable">f1</span>, <span class="cm-variable">f2</span>, <span class="cm-variable">f3</span>};</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 定义一个指向指针的指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">auto</span> <span class="cm-variable">pp</span> <span class="cm-operator">=</span> <span class="cm-operator">&</span><span class="cm-variable">p</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 41 | { |
39 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 直接调用函数指针数组</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">p</span>[<span class="cm-number">0</span>](<span class="cm-number">1</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">p</span>[<span class="cm-number">1</span>](<span class="cm-number">2</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">p</span>[<span class="cm-number">2</span>](<span class="cm-number">3</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 42 | int a = 10, b = 0xf, c = 0b10100; |
40 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 调用指向指针数组的指针</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> (<span class="cm-operator">*</span><span class="cm-variable">pp</span>)[<span class="cm-number">0</span>](<span class="cm-number">1</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">24</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> (<span class="cm-operator">*</span><span class="cm-variable">pp</span>)[<span class="cm-number">1</span>](<span class="cm-number">2</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">25</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> (<span class="cm-operator">*</span><span class="cm-variable">pp</span>)[<span class="cm-number">2</span>](<span class="cm-number">3</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">26</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">27</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">28</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 43 | cout << a << b << c << endl; |
41 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">29</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">double</span> <span class="cm-variable-3">*</span><span class="cm-def">f1</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">i</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">30</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">31</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">static</span> <span class="cm-variable-3">double</span> <span class="cm-variable">d</span> <span class="cm-operator">=</span> <span class="cm-number">1.1</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">32</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-operator">&</span><span class="cm-variable">d</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">33</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">34</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 44 | return 0; |
42 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">35</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">double</span> <span class="cm-variable-3">*</span><span class="cm-def">f2</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">i</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">36</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">37</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">static</span> <span class="cm-variable-3">double</span> <span class="cm-variable">d</span> <span class="cm-operator">=</span> <span class="cm-number">2.2</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">38</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-operator">&</span><span class="cm-variable">d</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">39</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">40</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 45 | }</code></pre> |
43 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">41</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable-3">double</span> <span class="cm-variable-3">*</span><span class="cm-def">f3</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">i</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">42</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">43</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">static</span> <span class="cm-variable-3">double</span> <span class="cm-variable">d</span> <span class="cm-operator">=</span> <span class="cm-number">3.3</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">44</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-operator">&</span><span class="cm-variable">d</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">45</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1170px;"></div><div class="CodeMirror-gutters" style="height: 1170px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><h1 id='第八章'><span>第八章</span></h1><h2 id='内联函数'><span>内联函数</span></h2><p><span>内联函数是 C++为提高程序运行速度而做的一项改进。</span><strong><span>常规函数与内联函数区别不在于编写方式,而在于 C++编译器如何将它们组合到程序中。</span></strong><span>要了解它们的区别,必须深入到程序内部。</span></p><p><span>编译过程的最终产品是可执行程序,由一组机器语言指令组成。运行程序时,操作系统将指令载入内存,因而每条指令都有其特定的内存地址。计算机随后一一调用执行,或者有时候向前/向后跳转到特定地址,如循环、条件判断、分支语句等。</span></p><p><span>常规函数调用也是一个跳转,在此过程中,程序首先将跳转后需要执行的指令的地址压栈,并将现在的寄存器中参数复制到堆栈(为此保留的内存区),跳转到目标函数的地址,执行该函数,在遇到返回指令时,返回地址出栈,程序跳转到该地址,然后将参数复制回来,从而使原来的函数继续进行。</span></p><p><span>而内联函数的编译代码是与其他程序的代码“内联”的,换言之,编译器将使用内联函数的代码替换掉此处的函数调用,直接 copy 进来了。由于缺少了复制和跳转的过程,因而执行速度较快,但同时占据更多内存,调用几次该函数,该函数代码就被抄写几份。使用过程中需要综合考虑是否使用内联函数。</span></p><p><strong><span>要使用内联函数,必须采取下列措施之一:</span></strong></p><ul><li><p><span>在函数原型前加关键字</span><kbd><span>inline</span></kbd></p></li><li><p><span>在函数定义前加关键字</span><kbd><span>inline</span></kbd></p></li></ul><p><span>程序员做出内联请求时,编译器不一定同意(p.s.到底是我写代码还是编译器写代码?气抖冷!),它可能认为函数过大或者注意到有递归(众所周知,内敛这个形式不能递归的),或者有些编译器没有启用或实现内联这一功能。</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>23</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 46 | <ul> |
44 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">// 这是一个内联函数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">inline</span> <span class="cm-variable-3">double</span> <span class="cm-def">square</span>(<span class="cm-variable-3">double</span> <span class="cm-variable">x</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">x</span> <span class="cm-operator">*</span> <span class="cm-variable">x</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 47 | <li><code>cout</code>提供控制符以八进制、十进制与十六进制显示整数。</li> |
45 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">double</span> <span class="cm-variable">a</span>, <span class="cm-variable">b</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">double</span> <span class="cm-variable">c</span> <span class="cm-operator">=</span> <span class="cm-number">13.0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 48 | </ul> |
46 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">a</span> <span class="cm-operator">=</span> <span class="cm-variable">square</span>(<span class="cm-number">5.0</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">b</span> <span class="cm-operator">=</span> <span class="cm-variable">square</span>(<span class="cm-number">4.5</span> <span class="cm-operator">+</span> <span class="cm-number">7.5</span>); <span class="cm-comment">// 可以传递表达式</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 49 | <pre><code>#include <iostream> |
47 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"a = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">a</span> <span class="cm-operator"><<</span> <span class="cm-string">", b = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">b</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"c = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">c</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">", c squared = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">square</span>(<span class="cm-variable">c</span><span class="cm-operator">++</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Now c = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">c</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">23</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 598px;"></div><div class="CodeMirror-gutters" style="height: 598px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>输出结果为:</span></p><blockquote><p><span>a = 25, b = 144</span></p><p><span>c = 13, c squared = 169</span></p><p><span>Now c = 14</span></p></blockquote><p><span>输出表明,内联函数与普通函数一样,按值传递参数,参数为表达式则传递表达式的值。</span></p><p><span>C 语言中也可以像这样,不写函数原型,直接以函数定义充当函数原型。</span></p><h2 id='内联的原始实现c-中的define'><span>内联的原始实现:C 中的</span><kbd><span>#define</span></kbd></h2><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>12</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <stdio.h></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#define square(x) x*x</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 50 | using namespace std; |
48 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">double</span> <span class="cm-variable">a</span>, <span class="cm-variable">b</span>, <span class="cm-variable">c</span> <span class="cm-operator">=</span> <span class="cm-number">3</span>, <span class="cm-variable">d</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">a</span> <span class="cm-operator">=</span> <span class="cm-variable">square</span>(<span class="cm-number">5.0</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">b</span> <span class="cm-operator">=</span> <span class="cm-variable">square</span>(<span class="cm-number">4</span> <span class="cm-operator">+</span> <span class="cm-number">5</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">d</span> <span class="cm-operator">=</span> <span class="cm-variable">square</span>(<span class="cm-variable">c</span><span class="cm-operator">++</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">printf</span>(<span class="cm-string">"a = %lf\nb = %lf\nd = %lf\n"</span>, <span class="cm-variable">a</span>, <span class="cm-variable">b</span>, <span class="cm-variable">d</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 312px;"></div><div class="CodeMirror-gutters" style="height: 312px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>这并不是通过传递参数实现,而是通过文本替换实现的——</span><mjx-container class="MathJax" jax="SVG" style="position: relative;"><svg xmlns="http://www.w3.org/2000/svg" width="1.294ex" height="1.025ex" role="img" focusable="false" viewBox="0 -442 572 453" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" style="vertical-align: -0.025ex;"><defs><path id="MJX-9-TEX-I-1D465" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><use data-c="1D465" xlink:href="#MJX-9-TEX-I-1D465"></use></g></g></g></svg><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>x</mi></math></mjx-assistive-mml></mjx-container><script type="math/tex">x</script><span>是“参数”的符号标记。</span></p><p><span>上例只有</span><mjx-container class="MathJax" jax="SVG" style="position: relative;"><svg xmlns="http://www.w3.org/2000/svg" width="1.197ex" height="1.02ex" role="img" focusable="false" viewBox="0 -441 529 451" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" style="vertical-align: -0.023ex;"><defs><path id="MJX-10-TEX-I-1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="scale(1,-1)"><g data-mml-node="math"><g data-mml-node="mi"><use data-c="1D44E" xlink:href="#MJX-10-TEX-I-1D44E"></use></g></g></g></svg><mjx-assistive-mml unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>a</mi></math></mjx-assistive-mml></mjx-container><script type="math/tex">a</script><span>输出正确,可以用括号进行改进:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>1</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#define square(x) ((x) * (x))</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 26px;"></div><div class="CodeMirror-gutters" style="height: 26px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><p><span>即使如此,后两者依然输出错误,即无法实现按值传递。所以,使用内联函数应当尽可能考虑使用 C++的内联,而不是 C 的宏。</span></p><h2 id='引用变量'><span>引用变量</span></h2><h3 id='引用变量是什么能吃吗'><span>引用变量是什么?能吃吗?</span></h3><p><span>引用变量是已定义变量的一个别名。话不多说,上例程。</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>12</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">n</span> <span class="cm-operator">=</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-operator">&</span><span class="cm-variable">r</span> <span class="cm-operator">=</span> <span class="cm-variable">n</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">r</span> <span class="cm-operator">=</span> <span class="cm-number">1</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"n = "</span> <span class="cm-operator"><<</span> <span class="cm-variable">n</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Addr r is "</span> <span class="cm-operator"><<</span> <span class="cm-operator">&</span><span class="cm-variable">r</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"Addr n is "</span> <span class="cm-operator"><<</span> <span class="cm-operator">&</span><span class="cm-variable">n</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 312px;"></div><div class="CodeMirror-gutters" style="height: 312px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>运行结果如下:</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang=""><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>3</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">n = 1</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">Addr r is 0x7ffce76ff48c</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">Addr n is 0x7ffce76ff48c</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 78px;"></div><div class="CodeMirror-gutters" style="height: 78px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><p><span>由结果可知,</span><strong><span>r 只是 n 的一个别名,在修改 r 的时候实质上就是在修改 n。二者的地址是相同的。</span></strong></p><p><strong><span>请注意:</span></strong></p><ul><li><p><span>例程第 6 行的</span><code>&</code><span>并非取地址符,而是将 r 声明为一个</span><kbd><span>int&</span></kbd><span>型的变量;而在第 9/10 行的</span><code>&</code><span>则是取地址符。</span></p></li><li><p><span>引用变量必须在声明的时候进行初始化,一旦初始化,即宣誓效忠,至死不渝,是无法改变的。换言之,</span><kbd><span>int &r = n</span></kbd><span>是</span><kbd><span>int* const *pr = n</span></kbd><span>的一个封装表示而已。</span></p></li></ul><h3 id='引用变量作函数参数'><span>引用变量作函数参数</span></h3><p><span>在 C/C++一般的函数调用中,参数都是按值传递,即 copy 一份送到调用函数里使,即使做出了更改也不会直接影响原函数里的值,除非用返回值将其返回。有时候一个函数本来有自己需要返回的东西,又想把这个量修改了,就不好办了(用</span><kbd><span>pair</span></kbd><span>或者结构体,多少有点麻烦,还要为此创建一个类型)。这时候就可以考虑引用变量。</span></p><h3 id='c-风格字符串作-string-对象引用参数'><span>C-风格字符串作 string 对象引用参数</span></h3><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>14</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 51 | int main() |
49 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">const</span> <span class="cm-variable">string</span> <span class="cm-operator">&</span><span class="cm-variable">fuck</span>(<span class="cm-variable">string</span> <span class="cm-operator">&</span><span class="cm-variable">s1</span>, <span class="cm-keyword">const</span> <span class="cm-variable">string</span> <span class="cm-operator">&</span><span class="cm-variable">s2</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">s1</span> <span class="cm-operator">=</span> <span class="cm-variable">s2</span> <span class="cm-operator">+</span> <span class="cm-variable">s1</span> <span class="cm-operator">+</span> <span class="cm-variable">s2</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">s1</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">string</span> <span class="cm-variable">s1</span> <span class="cm-operator">=</span> <span class="cm-string">"Hello"</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">fuck</span>(<span class="cm-variable">s1</span>, <span class="cm-string">", World!\n"</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 364px;"></div><div class="CodeMirror-gutters" style="height: 364px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>程序可以接受将 C-风格字符串赋值给</span><kbd><span>string&</span></kbd><span>。</span></p><p><span>首先,</span><kbd><span>string</span></kbd><span>类定义了</span><kbd><span>char</span><span>*</span></kbd><span>到</span><kbd><span>string</span></kbd><span>的转换,因而可以使用字符数组初始化字符串;</span></p><p><span>其次,类型为 const 引用的形参有一个属性:</span><strong><span>在形参与实参不匹配但可以转换的时候,程序会创建临时变量进行匹配,然后传参过去。</span></strong><span>换言之,程序调用之前创建一个临时</span><kbd><span>string</span></kbd><span>,把引用传递过去。</span></p><h3 id='对象继承和引用'><span>对象、继承和引用</span></h3><p><strong><span>使得能将特性从一个类传递给另一个类的语言特性称为继承。</span></strong><span>继承的另一个特性是,基类引用可以指向派生类对象而无需进行强制转换。这种特性的实际结果为,派生类中可以定义一个以基类引用为参数的函数,调用该函数时,既能以基类为参数,也可以派生类为参数。</span></p><p><span>以</span><kbd><span>ofstream</span></kbd><span>与</span><kbd><span>ostream</span></kbd><span>为例,前者为派生类,后者为基类,因为前者建立在后者基础之上。派生类继承了基类的方法,这意味着</span><kbd><span>ofstream</span></kbd><span>可以使用</span><kbd><span>ostream</span></kbd><span>的特性,如格式化方法和输出运算符;参数类型为</span><kbd><span>ostream&</span></kbd><span>的函数既可以接收</span><kbd><span>ostream</span></kbd><span>对象(如 cout),也可以接收已经声明的</span><kbd><span>ofstream</span></kbd><span>对象为参数。</span></p><h3 id='何时使用引用'><span>何时使用引用</span></h3><p><span>使用引用参数的原因:</span></p><ul><li><p><span>能修改调用函数的数据对象</span></p></li><li><p><span>通过传递引用而非整个数据对象,提高运行速度。</span></p></li></ul><p><span>当数据对象较大(如结构体、类对象),第二个因素占主要,这也是使用指针的原因,因为引用实际上是指针的另一个接口。</span></p><p><span>什么时候使用指针、什么时候使用按值传递呢?</span> | 52 | { |
50 | <span>对于使用传递的值而不作修改的:</span></p><ul><li><p><span>数据量小,按值传递</span></p></li><li><p><span>是数组,指针传递,这是唯一办法,并将指针声明为指向 const 的指针</span></p></li><li><p><span>数据对象是较大的结构体,使用 const 引用或 const 指针</span></p></li><li><p><span>是类对象,使用 const 引用</span></p></li></ul><p><span>对于修改调用函数数据的函数:</span></p><ul><li><p><span>修改的是内置数据类型,使用指针</span></p></li><li><p><span>是数组,就只能用指针</span></p></li><li><p><span>是结构体,用指针或引用</span></p></li><li><p><span>是类对象,用引用</span></p></li></ul><h2 id='函数多态'><span>函数多态</span></h2><p><span>函数多态是 C++在 C 基础上增加的功能。</span></p><ul><li><p><span>默认参数允许以不同数目的参数调用同一函数</span></p></li><li><p><span>重载允许使用多个同名的函数。</span></p></li></ul><h3 id='默认参数'><span>默认参数</span></h3><p><span>默认参数指函数调用中省略实参时自动使用的实参值。</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>14</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">// 一个使用默认参数的例子</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">add</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">a</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">b</span> <span class="cm-operator">=</span> <span class="cm-number">1</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">c</span> <span class="cm-operator">=</span> <span class="cm-number">2</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">a</span> <span class="cm-operator">+</span> <span class="cm-variable">b</span> <span class="cm-operator">+</span> <span class="cm-variable">c</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">add</span>(<span class="cm-number">5</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>; <span class="cm-comment">// 8</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">add</span>(<span class="cm-number">5</span>, <span class="cm-number">6</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>; <span class="cm-comment">// 13</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">add</span>(<span class="cm-number">5</span>, <span class="cm-number">6</span>, <span class="cm-number">7</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>; <span class="cm-comment">// 18</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 364px;"></div><div class="CodeMirror-gutters" style="height: 364px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><strong><span>对于带参数列表(有形参)的函数,必须从右向左添加默认值,即所有有默认值的形参必须在所有无默认值形参的右边。使用时,传递的实参被从左到右依次赋给形参,而不得跳过任何形参。</span></strong></p><h3 id='函数重载'><span>函数重载</span></h3><p><span>函数重载指可以有多个同名函数,它们</span><strong><span>以参数列表(形参,不包括返回值类型)为区别</span></strong><span>。C++使用上下文来确定要使用的重载函数版本。</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>20</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//一个函数重载示例程序</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 53 | using namespace std; |
51 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">add</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">a</span>, <span class="cm-variable-3">int</span> <span class="cm-variable">b</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">a</span> <span class="cm-operator">+</span> <span class="cm-variable">b</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 54 | int chest = 42; |
52 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">double</span> <span class="cm-def">add</span>(<span class="cm-variable-3">double</span> <span class="cm-variable">a</span>, <span class="cm-variable-3">double</span> <span class="cm-variable">b</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">a</span> <span class="cm-operator">+</span> <span class="cm-variable">b</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 55 | int waist = 42; |
53 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">add</span>(<span class="cm-number">1</span>, <span class="cm-number">2</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">add</span>(<span class="cm-number">1.1</span>, <span class="cm-number">2.2</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 520px;"></div><div class="CodeMirror-gutters" style="height: 520px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><blockquote><p><span>仅当在函数执行基本相同的任务而使用不同的数据类型时,才适合重载</span></p><p><span>重载虽好,可不要贪杯哦~</span></p></blockquote><h2 id='函数模板'><span>函数模板</span></h2><p><span>函数模板是通用的函数描述,使用泛型来定义函数,其中的泛型可用于指定的具体类型(即</span><kbd><span>int</span></kbd><span>/</span><kbd><span>double</span></kbd><span>等)替换。通过将类型作为参数传递给模板,可使编译器生成该类型的函数。</span></p><blockquote><p><span>少扯淡,一个代码就明白了</span></p></blockquote><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>22</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//一个使用函数模板的历次</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 56 | int inseam = 42; |
54 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">typename</span> <span class="cm-variable">T</span><span class="cm-operator">></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">T</span> <span class="cm-def">max5</span>(<span class="cm-variable">T</span> <span class="cm-variable">a</span>[])</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">T</span> <span class="cm-variable">max</span> <span class="cm-operator">=</span> <span class="cm-variable">a</span>[<span class="cm-number">0</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span> (<span class="cm-variable-3">int</span> <span class="cm-variable">i</span> <span class="cm-operator">=</span> <span class="cm-number">1</span>; <span class="cm-variable">i</span> <span class="cm-operator"><</span> <span class="cm-number">5</span>; <span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span> (<span class="cm-variable">a</span>[<span class="cm-variable">i</span>] <span class="cm-operator">></span> <span class="cm-variable">max</span>)</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">max</span> <span class="cm-operator">=</span> <span class="cm-variable">a</span>[<span class="cm-variable">i</span>];</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-variable">max</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 57 | cout << "Monsieur cuts a striking figure !" <<endl; |
55 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">17</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">a</span>[<span class="cm-number">5</span>] <span class="cm-operator">=</span> {<span class="cm-number">1</span>, <span class="cm-number">2</span>, <span class="cm-number">3</span>, <span class="cm-number">4</span>, <span class="cm-number">5</span>};</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">double</span> <span class="cm-variable">b</span>[<span class="cm-number">5</span>] <span class="cm-operator">=</span> {<span class="cm-number">1.1</span>, <span class="cm-number">2.2</span>, <span class="cm-number">3.3</span>, <span class="cm-number">4.4</span>, <span class="cm-number">5.5</span>};</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">19</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">max5</span>(<span class="cm-variable">a</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">20</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">max5</span>(<span class="cm-variable">b</span>) <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">22</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 572px;"></div><div class="CodeMirror-gutters" style="height: 572px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>第一行指出,要建立一个模板,类型命名为 T。关键字</span><kbd><span>template</span></kbd><span>和</span><kbd><span>typename</span></kbd><span>是必须的,但可以使用关键字</span><kbd><span>class</span></kbd><span>替代</span><kbd><span>typename</span></kbd><span>>。另外,必须使用尖括号。类型名可以随意写。</span></p><p><span>函数模板本身并不创建任何函数,只是告知编译器如何定义函数,由编译器探明和处理,各自按照模板新建一个函数。因而,函数模板不能缩短可执行程序,在上例中最终仍然是两个独立函数,并无函数模板。但模板的好处在于使生成多个同类型函数更简单可靠。</span></p><p><span>常见用法为</span><strong><span>将模板放在头文件中,在需要使用的地方包含头文件</span></strong><span>。</span></p><h3 id='模板重载'><span>模板重载</span></h3><p><span>模板满足了对不同类型使用同一种算法函数的需求,但并非所有类型都是用完全相同的算法。为满足此种需求,可以像重载常规函数一样重载模板定义,仍然需要满足参数列表不同便是了。</span></p><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 31px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 27px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>5</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -27px; width: 27px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">template</span><span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">T</span><span class="cm-operator">></span><span class="cm-comment">//一个模板</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">swap</span>(<span class="cm-variable">T</span> <span class="cm-operator">&</span><span class="cm-variable">a</span>,<span class="cm-variable">T</span> <span class="cm-operator">&</span><span class="cm-variable">b</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 58 | //所有设置,在更改之前将会一直延续 |
56 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 18px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">template</span><span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">T</span><span class="cm-operator">></span><span class="cm-comment">//另一个模板</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -27px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 18px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">swap</span>(<span class="cm-variable">T</span><span class="cm-operator">*</span> <span class="cm-variable">a</span>,<span class="cm-variable">T</span><span class="cm-operator">*</span> <span class="cm-variable">b</span>,<span class="cm-variable-3">int</span> <span class="cm-variable">n</span>);</span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 130px;"></div><div class="CodeMirror-gutters" style="height: 130px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 26px;"></div></div></div></div></pre><h3 id='模板的局限性'><span>模板的局限性</span></h3><p><span>模板局限性在于很可能无法处理某些数据类型。如赋值,一般类型赋值直接赋值即可,但数组则不可以;比较大小,一般数据类型可以直接比较,结构体则不行。</span></p><h3 id='具体化与实例化'><span>具体化与实例化</span></h3><p><strong><span>又是什么 JB 东西,似乎有用但似乎用处不大,先放着吧。</span></strong></p><h3 id='编译器选择哪个函数版本'><span>编译器选择哪个函数版本</span></h3><p><span>对于函数重载、函数模板和函数模板重载,C++需要一个定义良好的解析策略来确认调用哪一个函数定义,尤其是有多个参数的时候。此过程称为重载解析。</span></p><ul><li><p><span>创建候选函数列表,包含所有与被调用函数同名的函数与模板</span></p></li><li><p><span>使用候选函数列表,根据实参来创建可行函数列表</span></p></li><li><p><span>确定是否有最佳的可行函数,有则使用,无则报错。优先级如下:</span></p><ul><li><p><span>完全匹配,但</span><strong><span>常规函数优先于模板</span></strong></p></li><li><p><span>提升转换(</span><kbd><span>char</span></kbd><span>/</span><kbd><span>chort</span></kbd><span>--></span><kbd><span>int</span></kbd><span>,</span><kbd><span>float</span></kbd><span>--></span><kbd><span>double</span></kbd><span>)</span></p></li><li><p><span>标准转换(</span><kbd><span>int</span></kbd><span>--></span><kbd><span>char</span></kbd><span>,</span><kbd><span>long</span></kbd><span>--></span><kbd><span>double</span></kbd><span>)</span></p></li><li><p><span>用户定义的转换,如类声明中定义的转换。</span></p></li></ul></li></ul><blockquote><p><span>完全匹配时,允许某些无关紧要的转换,如下表。</span></p><figure><table><thead><tr><th><span>实参</span></th><th><span>形参</span></th></tr></thead><tbody><tr><td><span>Type</span></td><td><span>Type&</span></td></tr><tr><td><span>Type&</span></td><td><span>Type</span></td></tr><tr><td><span>Type[]</span></td><td><span>*</span><span>Type</span></td></tr><tr><td><span>Type(argument0list)</span></td><td><span>Type(</span><span>*</span><span>)(argument-list)</span></td></tr><tr><td><span>Type</span></td><td><span>const Type</span></td></tr><tr><td><span>Type</span></td><td><span>volatile Type</span></td></tr><tr><td><span>Type</span><span>*</span></td><td><span>const Type</span></td></tr><tr><td><span>Type</span><span>*</span></td><td><span>volatile Type</span></td></tr></tbody></table></figure></blockquote><pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 11px; left: 39px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 35px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre><div class="CodeMirror-linenumber CodeMirror-gutter-elt"><div>15</div></div></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -35px; width: 35px;"></div><div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">1</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//调用函数</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">2</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">may</span>(<span class="cm-string">'B'</span>);</span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 59 | //默认显示十进制 |
57 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">4</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//所有同名</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">5</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">may</span>(<span class="cm-variable-3">int</span>); <span class="cm-comment">// 1</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">6</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">float</span> <span class="cm-def">may</span>(<span class="cm-variable-3">float</span>, <span class="cm-variable-3">float</span> <span class="cm-operator">=</span> <span class="cm-number">3</span>); <span class="cm-comment">// 2</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">may</span>(<span class="cm-variable-3">char</span>); <span class="cm-comment">// 3</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">char</span> <span class="cm-variable-3">*</span><span class="cm-def">may</span>(<span class="cm-keyword">const</span> <span class="cm-variable-3">char</span> <span class="cm-variable-3">*</span>); <span class="cm-comment">// 4</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">char</span> <span class="cm-def">may</span>(<span class="cm-keyword">const</span> <span class="cm-variable-3">char</span> <span class="cm-operator">&</span>); <span class="cm-comment">// 5</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">10</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 60 | cout << "chest = " << chest << "(decimal for 42 ) " << endl; |
58 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">T</span><span class="cm-operator">></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">may</span>(<span class="cm-keyword">const</span> <span class="cm-variable">T</span> <span class="cm-operator">&</span>); <span class="cm-comment">// 6</span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 61 | cout << hex; // 显示十六进制 |
59 | </span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">template</span> <span class="cm-operator"><</span><span class="cm-keyword">class</span> <span class="cm-def">T</span><span class="cm-operator">></span></span></pre></div><div style="position: relative;"><div class="CodeMirror-gutter-wrapper" style="left: -35px;"><div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" style="left: 0px; width: 26px;">15</div></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">may</span>(<span class="cm-variable">T</span> <span class="cm-operator">*</span>); <span class="cm-comment">// 7</span></span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 390px;"></div><div class="CodeMirror-gutters" style="height: 390px;"><div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 34px;"></div></div></div></div></pre><p><span>由上述规则可以看出,优先级情况如下:</span></p><ul><li><p><span>完全匹配:3、5、6</span></p></li><li><p><span>提升转换:1</span></p></li><li><p><span>标准转换:2</span></p></li><li><p><span>不符合:4、7</span></p></li></ul><p><span>其中,3、5 是常规函数,优先级高于 6 模板。</span></p><p><span>有两个最佳选择的情况一般认为是错误的,但有特例。</span></p><ul><li><p><span>指向非 const 数据的指针和引用优先与非 const 指针和引用参数匹配,反之然</span></p></li><li><p><span>其中一个是非模板函数而另一个不是,此时废模板函数优先于模板函数(包括显式具体化)</span></p></li></ul> | 62 | cout << "'waist = " << waist <<"(hexadecimal for 42)" << endl; |
60 | 63 | cout << oct; // 十进制 | |
61 | <p class="time" style="color:antiquewhite">2023.3.30</p> | 64 | cout << "inseam = " << inseam <<: " (octal for 42 ) " << endl; |
65 | return 0 ; | ||
66 | }</code></pre> | ||
67 | <ul> | ||
68 | <li>通用字符名</li> | ||
69 | </ul> | ||
70 | <blockquote> | ||
71 | <p>ISO 10646,Unicode 与 UTF-8 的那些事</p> | ||
72 | </blockquote> | ||
73 | <ul> | ||
74 | <li>常量定义,建议使用<kbd>const</kbd>限定而非<kbd>#define</kbd>,且必须在定义时赋值,否则即乱码数字,后续无法修改。</li> | ||
75 | <li>浮点数赋值直接赋,不认识后缀 f</li> | ||
76 | <li><code>auto</code>声明,自动根据初始值类型推断变量类型。</li> | ||
77 | </ul> | ||
78 | <h1 id="第四章">第四章</h1> | ||
79 | <h2 id="数组">数组</h2> | ||
80 | <ul> | ||
81 | <li>数组创建,数组大小必须为常量,不能是变量。 | ||
82 | <ul> | ||
83 | <li>数组是一种复合类型,是依托于其他类型来创建的(C 称之为派生,而 C++对类关系使用派生这一术语)</li> | ||
84 | </ul> | ||
85 | </li> | ||
86 | <li>数组初始化,如果在定义时仅对一部分元素初始化,则其他元素将被设置为 0</li> | ||
87 | </ul> | ||
88 | <h2 id="字符串">字符串</h2> | ||
89 | <ul> | ||
90 | <li>拼接字符串常量。字符串过长时允许拼接字符串字面值。 | ||
91 | <ul> | ||
92 | <li>任两个由空白分隔符(空格、<code>\t</code>、<code>\n</code>)分割的字符串常量都会被自动拼接为一个。</li> | ||
93 | </ul> | ||
94 | </li> | ||
95 | <li><kbd>get</kbd>与<kbd>getline</kbd>,二者使用方式基本相同,只是前者继承 cin 的特性,不会读取换行符后再从字符串中删除,而是把换行符留在输入队列中。</li> | ||
96 | </ul> | ||
97 | <pre><code>/*在没有任何参数的情况下 | ||
98 | *cin.get()会读取下一个字符,即使是换行符 | ||
99 | *因此可用以清空*/ | ||
100 | cin.get(name , ArSize);// read first line | ||
101 | cin.get();// read newline | ||
102 | cin.get(dessert. Arsize ) ;// read second line | ||
103 | //前两行可以合并为: | ||
104 | //cin.get(name, ArSize).het()</code></pre> | ||
105 | <ul> | ||
106 | <li>其他类型字符的使用 | ||
107 | <ul> | ||
108 | <li><kbd>wchar_t</kbd></li> | ||
109 | <li><kbd>char16_t</kbd></li> | ||
110 | <li><kbd>char32_t</kbd></li> | ||
111 | </ul> | ||
112 | </li> | ||
113 | <li>C++<kbd>string</kbd>提供字符串翻转函数。</li> | ||
114 | </ul> | ||
115 | <h2 id="结构体">结构体</h2> | ||
116 | <ul> | ||
117 | <li>结构体初始化 | ||
118 | <ul> | ||
119 | <li>按声明顺序将列表声明为结构体初始化</li> | ||
120 | <li>指定对应初始化</li> | ||
121 | <li>构造函数初始化</li> | ||
122 | </ul> | ||
123 | </li> | ||
124 | </ul> | ||
125 | <pre><code>#include <iostream> | ||
126 | using namespace std; | ||
127 | |||
128 | struct student | ||
129 | { | ||
130 | int id; | ||
131 | string name; | ||
132 | short scores[3]; | ||
133 | void student(int id,string name,short scores[]) | ||
134 | { | ||
135 | this->id=id; | ||
136 | this->name=name; | ||
137 | for(char i=0;i<3;i++) | ||
138 | { | ||
139 | this->scores[i]=scores[i]; | ||
140 | } | ||
141 | } | ||
142 | }; | ||
143 | |||
144 | int main() | ||
145 | { | ||
146 | student a={2021110884,"QJGZ",150,150,150}; | ||
147 | strdent b={.id=2021110884,.name="陈一豪",.scores={150,150,150}}; | ||
148 | student c(2021110884,"QJGZ",{150,150,150}); | ||
149 | |||
150 | return 0; | ||
151 | }</code></pre> | ||
152 | <blockquote> | ||
153 | <p>注意,前两种方法不能使用在有构造函数的结构体中,否则会报错“指示符不能用于非聚合类型”。</p> | ||
154 | <p>对于所有非聚合类型,不能使用初始化列表(即用列表形式初始化,前两种方法是也)。</p> | ||
155 | <p>聚合类型定义如下:</p> | ||
156 | <ul> | ||
157 | <li>数组</li> | ||
158 | <li>不包含(构造函数、private 和 protect、基类、虚函数)的类、结构体和联合体</li> | ||
159 | </ul> | ||
160 | </blockquote> | ||
161 | <h2 id="共用体">共用体</h2> | ||
162 | <p>举例:一个小商品目录,一些商品 id 为字符串,另一些为数字:</p> | ||
163 | <pre><code>union id | ||
164 | { | ||
165 | long id_num; | ||
166 | char id_str[32]; | ||
167 | }; | ||
168 | struct good | ||
169 | { | ||
170 | char brand[20]; | ||
171 | int type; | ||
172 | id id_val; | ||
173 | };</code></pre> | ||
174 | <p>同时,有匿名共用体:</p> | ||
175 | <pre><code> | ||
176 | struct good | ||
177 | { | ||
178 | char brand[20]; | ||
179 | int type; | ||
180 | union | ||
181 | { | ||
182 | long id_num; | ||
183 | char id_str[32]; | ||
184 | } | ||
185 | };</code></pre> | ||
186 | <p>匿名共用体没有自己的名称,成员将成为位于同一位置的不同变量,被视为上一级的成员。</p> | ||
187 | <h2 id="枚举">枚举</h2> | ||
188 | <p><strong>啥 JB 东西,看不懂!!!</strong></p> | ||
189 | <h2 id="指针">指针</h2> | ||
190 | <ul> | ||
191 | <li><kbd>int*</kbd>被理解为一种复合类型而存在,但<kbd>int* a, b</kbd>被解释为一个指针和一个整型</li> | ||
192 | </ul> | ||
193 | <blockquote> | ||
194 | <p>哪个 TM 大聪明的主意?</p> | ||
195 | </blockquote> | ||
196 | <h3 id="指针数组与指针算术">指针、数组与指针算术</h3> | ||
197 | <p>指针与数组基本等价的原因在于指针算数和 C++内部处理方式。</p> | ||
198 | <p>算术:</p> | ||
199 | <ul> | ||
200 | <li>整型变量递增+1,指针变量递增加的是指向的类型的字节数。<strong>这同时表明,C++将数组名解释为地址。</strong></li> | ||
201 | <li>可以以相同的形式使用指针与数组名。 | ||
202 | <ul> | ||
203 | <li>方括号数组表示</li> | ||
204 | <li>加偏移量而后解引用</li> | ||
205 | </ul> | ||
206 | </li> | ||
207 | <li>注意: | ||
208 | <ul> | ||
209 | <li><strong>数组名直接取地址为整个数组作为内存块的地址,递增时加的是整块大小</strong></li> | ||
210 | <li><strong>数组名本身是首个元素的地址,递增时加的是元素大小</strong></li> | ||
211 | <li>二者初值相同</li> | ||
212 | </ul> | ||
213 | </li> | ||
214 | </ul> | ||
215 | <h2 id="变量存储方式">变量存储方式</h2> | ||
216 | <ul> | ||
217 | <li>局部存储</li> | ||
218 | <li>静态存储 | ||
219 | <ul> | ||
220 | <li>定义为全局变量</li> | ||
221 | <li>使用<kbd>static</kbd>关键字,如<kbd>static int c=3; </kbd></li> | ||
222 | </ul> | ||
223 | </li> | ||
224 | <li>动态存储</li> | ||
225 | </ul> | ||
226 | <h2 id="数组替代">数组替代</h2> | ||
227 | <ul> | ||
228 | <li><kbd>vector</kbd> | ||
229 | <ul> | ||
230 | <li>分配在自由存储区或堆中。</li> | ||
231 | <li>功能强大,效率略低</li> | ||
232 | </ul> | ||
233 | </li> | ||
234 | <li><kbd>array</kbd> | ||
235 | <ul> | ||
236 | <li>长度固定如数组,和数组一样分配在栈上而非自由存储区,因而效率同于数组,但更方便安全。</li> | ||
237 | </ul> | ||
238 | </li> | ||
239 | </ul> | ||
240 | <pre><code>#include <array> | ||
241 | using namespace std; | ||
242 | |||
243 | int main() | ||
244 | { | ||
245 | array<int,5> a; | ||
246 | int i; | ||
247 | for(i=0;i<5;i++) | ||
248 | { | ||
249 | cin>>a[i]; | ||
250 | } | ||
251 | for(i=0;i<5;i++) | ||
252 | { | ||
253 | cout<<a[i]; | ||
254 | } | ||
255 | return 0; | ||
256 | }</code></pre> | ||
257 | <h1 id="第五章">第五章</h1> | ||
258 | <h2 id="递增递减运算符">递增递减运算符</h2> | ||
259 | <ul> | ||
260 | <li>写在后边,则变量先使用,再加/减</li> | ||
261 | <li>写在前边,则变量先加/减,再使用</li> | ||
262 | <li>避免使用不完整的表达式</li> | ||
263 | </ul> | ||
264 | <pre><code> //完整的表达式 | ||
265 | i=0 | ||
266 | while(i++<10) | ||
267 | { | ||
268 | cout<<i<<endl; | ||
269 | } | ||
270 | /*在上例中,先执行判断,而后递增,再输出,因而输出结果为[1,10] | ||
271 | *这是因为i++<10本身是一个完整表达式 | ||
272 | */ | ||
273 | |||
274 | //不完整表达式 | ||
275 | y=(4+x++)+(6+x++); | ||
276 | /*上式中,(4+x++)并不是一个完整表达式,无法保证执行完本处计算后x即刻+1 | ||
277 | *因而整条语句结果并不确定 | ||
278 | */ | ||
279 | </code></pre> | ||
280 | <blockquote> | ||
281 | <p>解释:</p> | ||
282 | <ul> | ||
283 | <li>副作用指计算表达式时对某些东西进行了修改</li> | ||
284 | <li>顺序点指程序过程中一个点,在这里将在进入下一步之前对所有副作用进行评估。</li> | ||
285 | </ul> | ||
286 | <p>在 C++中,语句的分号是一个顺序点,在下一步之前会把所有副作用造成的修改弄到位。 上例中,前者即有顺序点,执行之前就完成了副作用;后者顺序点在分号,因而副作用结果并不确定。</p> | ||
287 | </blockquote> | ||
288 | <p>本身即为运算表达式,有返回值,返回值即上所谓“使用”。</p> | ||
289 | <h3 id="指针与递增递减">指针与递增递减</h3> | ||
290 | <p>递增递减作用不赘。</p> | ||
291 | <p>前缀递增递减与解引用运算优先级相同,因而从内向外解释:</p> | ||
292 | <pre><code> int a[2]={1,2},*pt=a; | ||
293 | cout<<*++pt<<*(++pt)<<endl; | ||
294 | //输出结果,二者相等,即*++pt先执行递增,而后经过顺序点,再解引用,实际为a[1]=2</code></pre> | ||
295 | <p>后缀递增递减优先级高于解引用,因而*pt++结果与上亦同。</p> | ||
296 | <h2 id="逗号运算符">逗号运算符</h2> | ||
297 | <p>逗号运算符允许把两个表达式放一行,表达式的值是后半句的值。</p> | ||
298 | <blockquote> | ||
299 | <p>普通赋值运算式的值为右值。</p> | ||
300 | </blockquote> | ||
301 | <pre><code>#include<iostream> | ||
302 | using namespace std; | ||
303 | int main() | ||
304 | { | ||
305 | int a; | ||
306 | a=1,2; | ||
307 | cout<<a<<endl;//输出1,2不起作用 | ||
308 | a=(1,2); | ||
309 | cout<<a<<endl;//输出2 | ||
310 | return 0; | ||
311 | }</code></pre> | ||
312 | <h2 id="循环">循环</h2> | ||
313 | <p><kbd>for</kbd>循环与<kbd>while</kbd>循环的本质是相同的:</p> | ||
314 | <pre><code>for(init-expression; test-expression; update-expression) | ||
315 | { | ||
316 | statements | ||
317 | } | ||
318 | |||
319 | //等价于下述表达 | ||
320 | init-expression; | ||
321 | while (test-expression) | ||
322 | { | ||
323 | statements; | ||
324 | update-expression; | ||
325 | }</code></pre> | ||
326 | <p>区别:</p> | ||
327 | <ul> | ||
328 | <li>在<kbd>for</kbd>循环中省略测试表达式时默认为 true,而<kbd>while</kbd>中禁止此种行为</li> | ||
329 | <li>在循环体中有<kbd>continue</kbd>语句时,二者表现不再完全等价,稍有不同</li> | ||
330 | </ul> | ||
331 | <h2 id="循环与文本输入">循环与文本输入</h2> | ||
332 | <ul> | ||
333 | <li>逐个读取字符需要检查遇到的每个字符包括空格、制表、换行等非显示字符。此时应当使用<kbd>cin.get()</kbd>函数。</li> | ||
334 | <li>函数<kbd>cin.get(ch)</kbd>读取输入中的下一个字符(包括空格)并赋值给 ch,可以替换<kbd>cin>>ch</kbd>。</li> | ||
335 | </ul> | ||
336 | <h2 id="文件尾eof条件">文件尾(EOF)条件</h2> | ||
337 | <h3 id="重要性">重要性</h3> | ||
338 | <ul> | ||
339 | <li>很多操作系统(包括 Unix、Linux 和 Windows 命令提示符模式)都支持重定向,允许用文件替换键盘输入。</li> | ||
340 | </ul> | ||
341 | <blockquote> | ||
342 | <p>例如,假设在 Windows 中有一个名为 gofish.exe 的可执行程序和一个名为 fishtale 的文本文件,则可以在命令提示符模式下输入下面的命令:</p> | ||
343 | <p>gofish < fishtale</p> | ||
344 | <p>来实现以文本文件代替输入。</p> | ||
345 | </blockquote> | ||
346 | <ul> | ||
347 | <li>很多操作系统都允许通过键盘来模拟文件尾条件。 | ||
348 | <ul> | ||
349 | <li>在 Unix 中,可以在行首按下 Ctrl+D 来实现;</li> | ||
350 | <li>在 Windows 命令提示符模式下,可以在任意位置放 Ctrl+Z 和 Enter。</li> | ||
351 | <li>有些 C++实现支持类似的行为,即使底层操作系统并不支持。</li> | ||
352 | </ul> | ||
353 | </li> | ||
354 | </ul> | ||
355 | <blockquote> | ||
356 | <p>键盘输入的 EOF 概念实际上是命令行环境遗留边倒下来的。</p> | ||
357 | <p>然而:</p> | ||
358 | <ul> | ||
359 | <li>用于 Mac 的 Symantec C++模拟了 Unix,将 Ctrl+D 视为仿真的 EOF</li> | ||
360 | <li>Metrowerks Codewarrior 能够在 Macintosh 和 Windows 环境下识别 Ctr1+Z</li> | ||
361 | <li>用于 PC 的 Microsoft Visual C++、Borland C++ 5.5 和 GNU C++都能够识别行首的 Ctrl+Z,但用户必须随后按下回车键。</li> | ||
362 | </ul> | ||
363 | <p>总之,很多 PC 编程环绕都将 CtrI+Z 视为模拟的 EOF,但具体细节(必须在行首还是可以在任何位置,是否必须按下回车键等)各不相同。</p> | ||
364 | </blockquote> | ||
365 | <ul> | ||
366 | <li>如果编程环境能识别 EOF,则既可以使用重定向文件输入也可以用键盘,岂不美哉?</li> | ||
367 | </ul> | ||
368 | <h3 id="实现">实现</h3> | ||
369 | <p>检测到 EOF 后,cin 将两位(<kbd>eofbit</kbd>与<kbd>failbit</kbd>)均设置为 1。(可通过成员函数<kbd>bool cin.eof()</kbd>和<kbd>bool | ||
370 | cin.fail()</kbd>查看情况,且是在读取之后查看。)</p> | ||
371 | <h1 id="第六章">第六章</h1> | ||
372 | <h2 id="逻辑运算符相关">逻辑运算符相关</h2> | ||
373 | <ul> | ||
374 | <li>逻辑与/或的优先级均低于关系运算符 | ||
375 | <ul> | ||
376 | <li>逻辑与的优先级高于逻辑或</li> | ||
377 | </ul> | ||
378 | </li> | ||
379 | <li>逻辑非的优先级高于所有关系运算符和算术运算符,因而要对表达式求反必须括起来。</li> | ||
380 | <li>另一套表示方式</li> | ||
381 | </ul> | ||
382 | <table> | ||
383 | <thead> | ||
384 | <tr class="header"> | ||
385 | <th>运算符</th> | ||
386 | <th>另一种表示</th> | ||
387 | </tr> | ||
388 | </thead> | ||
389 | <tbody> | ||
390 | <tr class="odd"> | ||
391 | <td>&&</td> | ||
392 | <td>and</td> | ||
393 | </tr> | ||
394 | <tr class="even"> | ||
395 | <td>||</td> | ||
396 | <td>or</td> | ||
397 | </tr> | ||
398 | <tr class="odd"> | ||
399 | <td>!</td> | ||
400 | <td>not</td> | ||
401 | </tr> | ||
402 | </tbody> | ||
403 | </table> | ||
404 | <h2 id="字符函数库">字符函数库</h2> | ||
405 | <p>cctype(C 语言中的 ctype.h)可以用来确定字符是否为大/小写字母、数字、标点等。其优点在于更简单、更通用(字母、数字之类在不同的编码方式之下不一定都像 ASCII | ||
406 | 中一样的连续分布)。包含的函数如下:</p> | ||
407 | <pre><code>namespace std { | ||
408 | int isalnum(int c); | ||
409 | int isalpha(int c); | ||
410 | int isblank(int c); | ||
411 | int iscntrl(int c); | ||
412 | int isdigit(int c); | ||
413 | int isgraph(int c); | ||
414 | int islower(int c); | ||
415 | int isprint(int c); | ||
416 | int ispunct(int c); | ||
417 | int isspace(int c); | ||
418 | int isupper(int c); | ||
419 | int isxdigit(int c); | ||
420 | int tolower(int c); | ||
421 | int toupper(int c); | ||
422 | }</code></pre> | ||
423 | <h1 id="第七章">第七章</h1> | ||
424 | <h2 id="基础知识">基础知识</h2> | ||
425 | <ul> | ||
426 | <li>函数原型:说明函数名、形参类型/名称、返回值类型 | ||
427 | <ul> | ||
428 | <li>其实就是<span class="math inline"><em>m</em><em>a</em><em>i</em><em>n</em>()</span>之前的函数声明</li> | ||
429 | <li>函数原型中的函数特征标(参数列表)可以省略标识符(形参名称)而只是指出其类型</li> | ||
430 | </ul> | ||
431 | </li> | ||
432 | </ul> | ||
433 | <blockquote> | ||
434 | <p><sub>其实就是那个二锅头,兑的那个白开水</sub></p> | ||
435 | </blockquote> | ||
436 | <ul> | ||
437 | <li>函数定义:函数的本体实现</li> | ||
438 | </ul> | ||
439 | <h2 id="函数与数组">函数与数组</h2> | ||
440 | <pre><code>//函数定义 | ||
441 | int sum_arr(int arr[], int n);//对数组中元素求和 | ||
442 | |||
443 | //函数调用 | ||
444 | int a[10]={……};//一堆破数 | ||
445 | int sum=sum_arr(a,10);</code></pre> | ||
446 | <p>以上定义的函数,<strong>第一个形参是指针而非数组</strong>,但可以当做数组使用。</p> | ||
447 | <p><strong>原因:</strong>C++与 C | ||
448 | 一样,将数组名视为指针,指向第一个元素地址,对应元素大小为单个元素大小,详前。(相比之下,<kbd>&a</kbd>虽然也是指向首地址,但大小是整块数组的大小。)因而第一个形参实际是<kbd>int* | ||
449 | arr</kbd>,即定义应当为:</p> | ||
450 | <pre><code>int sum_arr(int* arr, int n);</code></pre> | ||
451 | <p>这证明两种形参声明同时正确。<strong>在 C++中,<kbd>int* arr</kbd>与<kbd>int | ||
452 | arr[]</kbd>当且仅当出现在函数头或函数原型的时候,含义才相同</strong>。它们都意味着 arr 是一个<kbd>int*</kbd>。</p> | ||
453 | <h2 id="使用数组区间的函数">使用数组区间的函数</h2> | ||
454 | <blockquote> | ||
455 | <p>屁话一堆,无非就是给定首尾元素的指针为形参,在中间作妖罢了。不说也罢。</p> | ||
456 | </blockquote> | ||
457 | <h2 id="指针与-const">指针与 const</h2> | ||
458 | <h3 id="将-const-用于指针">将 const 用于指针</h3> | ||
459 | <ul> | ||
460 | <li>指针指向<span class="math inline"><em>c</em><em>o</em><em>n</em><em>s</em><em>t</em></span>常量,防止修改</li> | ||
461 | <li>传参将指针本身声明为常量,防止修改指针指向的位置,但可以修改内容</li> | ||
462 | </ul> | ||
463 | <p>优点:</p> | ||
464 | <ul> | ||
465 | <li>避免无意见修改数据导致错误</li> | ||
466 | <li><kbd>const</kbd>可使函数能处理 const 与非 const 实参,否则只能接收后者。</li> | ||
467 | </ul> | ||
468 | <pre><code>//只能防止修改pt指向的值,但pt本身可以改成新地址 | ||
469 | int age=39; | ||
470 | const int* pt=&age; | ||
471 | int sage=80; | ||
472 | pt=&sage;//是可以的,不会出问题 | ||
473 | |||
474 | //下面两个是有区别滴,仔细看 | ||
475 | int sloth=3; | ||
476 | const int* ps=&sloth;//指向const int类型的指针 | ||
477 | int* const finger=&sloth;//指向int的const指针 | ||
478 | //前者如上例,不能修改内容,但能重新指向 | ||
479 | //后者则不能重新指向,但可以修改内容</code></pre> | ||
480 | <h2 id="二维数组作参数">二维数组作参数</h2> | ||
481 | <pre><code>int sum(int (*arr)[4], int size); | ||
482 | //等价于以下 | ||
483 | int aum(int arr[][4], int size); | ||
484 | |||
485 | //不能声明为 | ||
486 | int sum(int *arr[4], int size);</code></pre> | ||
487 | <p><strong>之所以不能声明为最后一个,是由于第一个形参应当是指向数组的指针,而不是单纯的二重指针。</strong>上述两个可用原型都指出,第一个形参类型实际上是指向 4 | ||
488 | 个元素的数组的指针。我之困惑于此也久矣,今乃得闻。</p> | ||
489 | <p>基于此,则传参之后仍可以二维数组待之,其原因为<kbd>arr[i]</kbd>被解释为<kbd>*(arr+i)</kbd>,是第 i 个数组,则<kbd>arr[i][j]</kbd>被解释为第 i | ||
490 | 个数组的第 j 个元素,即为二维数组。</p> | ||
491 | <h2 id="返回-c-风格字符串">返回 C 风格字符串</h2> | ||
492 | <p>听起来很扯淡,对吧?返回值怎么可能是数组类型?内部声明的数组在退出的时候不是就释放了吗?</p> | ||
493 | <p>那么,有没有一种可能,我是说可能,内部用<kbd>new</kbd>申请一段空间给<kbd>char*</kbd>,然后写完了返回,在主函数中用完了在<kbd>delete</kbd>呢?</p> | ||
494 | <h2 id="函数指针">函数指针</h2> | ||
495 | <p>为了实现函数指针,必须要完成:</p> | ||
496 | <ul> | ||
497 | <li>获取函数的首地址 | ||
498 | <ul> | ||
499 | <li>方法很简单,直接使用函数名即可。</li> | ||
500 | </ul> | ||
501 | </li> | ||
502 | </ul> | ||
503 | <blockquote> | ||
504 | <p>如<kbd>think()</kbd>是一个函数,则<kbd>think</kbd>就是该函数地址。要作为参数传递,必须传递函数名。<strong>要区分传递的是函数名还是函数返回值哦!</strong> | ||
505 | </p> | ||
506 | </blockquote> | ||
507 | <ul> | ||
508 | <li>声明一个函数指针 | ||
509 | <ul> | ||
510 | <li>声明一般指针需要说明指向的类型,函数指针也一样。这就是说,声明应指出函数的返回类型及其特征标(参数列表)。</li> | ||
511 | </ul> | ||
512 | </li> | ||
513 | <li>使用函数指针来调用函数</li> | ||
514 | </ul> | ||
515 | <p>例程如下:</p> | ||
516 | <pre><code>#include <iostream> | ||
517 | #include <string> | ||
518 | using namespace std; | ||
519 | |||
520 | bool hello(string name) | ||
521 | { | ||
522 | cout << "Hello, " << name << endl; | ||
523 | return true; | ||
524 | } | ||
525 | |||
526 | int main() | ||
527 | { | ||
528 | // 函数指针 | ||
529 | bool (*pf)(string); | ||
530 | // 函数参数为string型,返回值bool,指针名称pf。 | ||
531 | |||
532 | /* 上例是将<kbd>(*pf)</kbd>替代了<kbd>pam</kbd>,也就是说 | ||
533 | * <kbd>(*pf)</kbd>是函数 | ||
534 | *从而<kbd>pf</kbd>是函数指针。 | ||
535 | */ | ||
536 | |||
537 | /* 为提供正确的运算符优先级,应当用括号将`*`与`pf`括起来 | ||
538 | * 括号优先级高于`*`,从而: | ||
539 | * <kbd>*pf(string)</kbd>意味着<kbd>*pf(string)</kbd>是返回指针的函数 | ||
540 | * <kbd>(*pf)(string)</kbd>意味着<kbd>pf</kbd>是指向函数的指针 | ||
541 | */ | ||
542 | |||
543 | // 赋值 | ||
544 | pf = hello; | ||
545 | |||
546 | // 调用 | ||
547 | cout << pf("World") << endl; | ||
548 | }</code></pre> | ||
549 | <p>我又要骂人了,这什么东西,类型声明这么复杂?不用了不用了,享受不来。</p> | ||
550 | <p>没事,C++11 还有个特性叫<kbd>auto</kbd>,不是么?</p> | ||
551 | <p>上边的例程可以被改写成如下形式:</p> | ||
552 | <pre><code>#include <iostream> | ||
553 | #include <string> | ||
554 | using namespace std; | ||
555 | |||
556 | bool hello(string name) | ||
557 | { | ||
558 | cout << "Hello, " << name << endl; | ||
559 | return true; | ||
560 | } | ||
561 | |||
562 | int main() | ||
563 | { | ||
564 | //函数指针 | ||
565 | auto pf = hello; | ||
566 | // 调用 | ||
567 | cout << pf("World") << endl; | ||
568 | }</code></pre> | ||
569 | <p><del>这自动推断类型,多是一件美逝了!</del>让我们一起说,<strong>谢谢<kbd>auto</kbd>!</strong></p> | ||
570 | <p>另外,如果有若干函数返回类型和特征标都相同,都需要调用的话,何不考虑一下函数指针数组呢?更进一步地,为什么不选择创建一个指向整个函数指针数组的指针呢?</p> | ||
571 | <pre><code>#include <iostream> | ||
572 | using namespace std; | ||
573 | |||
574 | // 没错,函数原型可以不写形参名称的 | ||
575 | // 假设这段代码之外我们有函数的具体定义 | ||
576 | const double *f1(int); | ||
577 | const double *f2(int); | ||
578 | const double *f3(int); | ||
579 | |||
580 | int main() | ||
581 | { | ||
582 | // 定义一个指向函数的指针 | ||
583 | const double *(*p[3])(int) = {f1, f2, f3}; | ||
584 | // 定义一个指向指针的指针 | ||
585 | auto pp = &p; | ||
586 | |||
587 | // 直接调用函数指针数组 | ||
588 | cout << p[0](1) << endl; | ||
589 | cout << p[1](2) << endl; | ||
590 | cout << p[2](3) << endl; | ||
591 | |||
592 | // 调用指向指针数组的指针 | ||
593 | cout << (*pp)[0](1) << endl; | ||
594 | cout << (*pp)[1](2) << endl; | ||
595 | cout << (*pp)[2](3) << endl; | ||
596 | return 0; | ||
597 | } | ||
598 | |||
599 | const double *f1(int i) | ||
600 | { | ||
601 | static double d = 1.1; | ||
602 | return &d; | ||
603 | } | ||
604 | |||
605 | const double *f2(int i) | ||
606 | { | ||
607 | static double d = 2.2; | ||
608 | return &d; | ||
609 | } | ||
610 | |||
611 | const double *f3(int i) | ||
612 | { | ||
613 | static double d = 3.3; | ||
614 | return &d; | ||
615 | }</code></pre> | ||
616 | <h1 id="第八章">第八章</h1> | ||
617 | <h2 id="内联函数">内联函数</h2> | ||
618 | <p>内联函数是 C++为提高程序运行速度而做的一项改进。<strong>常规函数与内联函数区别不在于编写方式,而在于 C++编译器如何将它们组合到程序中。</strong>要了解它们的区别,必须深入到程序内部。 | ||
619 | </p> | ||
620 | <p>编译过程的最终产品是可执行程序,由一组机器语言指令组成。运行程序时,操作系统将指令载入内存,因而每条指令都有其特定的内存地址。计算机随后一一调用执行,或者有时候向前/向后跳转到特定地址,如循环、条件判断、分支语句等。 | ||
621 | </p> | ||
622 | <p>常规函数调用也是一个跳转,在此过程中,程序首先将跳转后需要执行的指令的地址压栈,并将现在的寄存器中参数复制到堆栈(为此保留的内存区),跳转到目标函数的地址,执行该函数,在遇到返回指令时,返回地址出栈,程序跳转到该地址,然后将参数复制回来,从而使原来的函数继续进行。 | ||
623 | </p> | ||
624 | <p>而内联函数的编译代码是与其他程序的代码“内联”的,换言之,编译器将使用内联函数的代码替换掉此处的函数调用,直接 copy | ||
625 | 进来了。由于缺少了复制和跳转的过程,因而执行速度较快,但同时占据更多内存,调用几次该函数,该函数代码就被抄写几份。使用过程中需要综合考虑是否使用内联函数。</p> | ||
626 | <p><strong>要使用内联函数,必须采取下列措施之一:</strong></p> | ||
627 | <ul> | ||
628 | <li>在函数原型前加关键字<kbd>inline</kbd></li> | ||
629 | <li>在函数定义前加关键字<kbd>inline</kbd></li> | ||
630 | </ul> | ||
631 | <p>程序员做出内联请求时,编译器不一定同意(p.s.到底是我写代码还是编译器写代码?气抖冷!),它可能认为函数过大或者注意到有递归(众所周知,内敛这个形式不能递归的),或者有些编译器没有启用或实现内联这一功能。 | ||
632 | </p> | ||
633 | <pre><code>#include <iostream> | ||
634 | using namespace std; | ||
635 | |||
636 | // 这是一个内联函数 | ||
637 | inline double square(double x) | ||
638 | { | ||
639 | return x * x; | ||
640 | } | ||
641 | |||
642 | int main() | ||
643 | { | ||
644 | double a, b; | ||
645 | double c = 13.0; | ||
646 | |||
647 | a = square(5.0); | ||
648 | b = square(4.5 + 7.5); // 可以传递表达式 | ||
649 | |||
650 | cout << "a = " << a << ", b = " << b << endl; | ||
651 | cout << "c = " << c; | ||
652 | cout << ", c squared = " << square(c++) << endl; | ||
653 | cout << "Now c = " << c << endl; | ||
654 | return 0; | ||
655 | }</code></pre> | ||
656 | <p>输出结果为:</p> | ||
657 | <blockquote> | ||
658 | <p>a = 25, b = 144</p> | ||
659 | <p>c = 13, c squared = 169</p> | ||
660 | <p>Now c = 14</p> | ||
661 | </blockquote> | ||
662 | <p>输出表明,内联函数与普通函数一样,按值传递参数,参数为表达式则传递表达式的值。</p> | ||
663 | <p>C 语言中也可以像这样,不写函数原型,直接以函数定义充当函数原型。</p> | ||
664 | <h2 id="内联的原始实现c-中的define">内联的原始实现:C 中的<kbd>#define</kbd></h2> | ||
665 | <pre><code>#include <stdio.h> | ||
666 | #define square(x) x*x | ||
667 | |||
668 | int main() | ||
669 | { | ||
670 | double a, b, c = 3, d; | ||
671 | a = square(5.0); | ||
672 | b = square(4 + 5); | ||
673 | d = square(c++); | ||
674 | printf("a = %lf\nb = %lf\nd = %lf\n", a, b, d); | ||
675 | return 0; | ||
676 | }</code></pre> | ||
677 | <p>这并不是通过传递参数实现,而是通过文本替换实现的——<span class="math inline"><em>x</em></span>是“参数”的符号标记。</p> | ||
678 | <p>上例只有<span class="math inline"><em>a</em></span>输出正确,可以用括号进行改进:</p> | ||
679 | <pre><code>#define square(x) ((x) * (x))</code></pre> | ||
680 | <p>即使如此,后两者依然输出错误,即无法实现按值传递。所以,使用内联函数应当尽可能考虑使用 C++的内联,而不是 C 的宏。</p> | ||
681 | <h2 id="引用变量">引用变量</h2> | ||
682 | <h3 id="引用变量是什么能吃吗">引用变量是什么?能吃吗?</h3> | ||
683 | <p>引用变量是已定义变量的一个别名。话不多说,上例程。</p> | ||
684 | <pre><code>#include <iostream> | ||
685 | using namespace std; | ||
686 | int main() | ||
687 | { | ||
688 | int n = 0; | ||
689 | int &r = n; | ||
690 | r = 1; | ||
691 | cout << "n = " << n << endl; | ||
692 | cout << "Addr r is " << &r << endl; | ||
693 | cout << "Addr n is " << &n << endl; | ||
694 | return 0; | ||
695 | }</code></pre> | ||
696 | <p>运行结果如下:</p> | ||
697 | <pre><code>n = 1 | ||
698 | Addr r is 0x7ffce76ff48c | ||
699 | Addr n is 0x7ffce76ff48c</code></pre> | ||
700 | <p>由结果可知,<strong>r 只是 n 的一个别名,在修改 r 的时候实质上就是在修改 n。二者的地址是相同的。</strong></p> | ||
701 | <p><strong>请注意:</strong></p> | ||
702 | <ul> | ||
703 | <li>例程第 6 行的<code>&</code>并非取地址符,而是将 r 声明为一个<kbd>int&</kbd>型的变量;而在第 9/10 | ||
704 | 行的<code>&</code>则是取地址符。</li> | ||
705 | <li>引用变量必须在声明的时候进行初始化,一旦初始化,即宣誓效忠,至死不渝,是无法改变的。换言之,<kbd>int &r = n</kbd>是<kbd>int* const *pr = | ||
706 | n</kbd>的一个封装表示而已。</li> | ||
707 | </ul> | ||
708 | <h3 id="引用变量作函数参数">引用变量作函数参数</h3> | ||
709 | <p>在 C/C++一般的函数调用中,参数都是按值传递,即 copy | ||
710 | 一份送到调用函数里使,即使做出了更改也不会直接影响原函数里的值,除非用返回值将其返回。有时候一个函数本来有自己需要返回的东西,又想把这个量修改了,就不好办了(用<kbd>pair</kbd>或者结构体,多少有点麻烦,还要为此创建一个类型)。这时候就可以考虑引用变量。 | ||
711 | </p> | ||
712 | <h3 id="c-风格字符串作-string-对象引用参数">C-风格字符串作 string 对象引用参数</h3> | ||
713 | <pre><code>#include <iostream> | ||
714 | using namespace std; | ||
715 | |||
716 | const string &fuck(string &s1, const string &s2) | ||
717 | { | ||
718 | s1 = s2 + s1 + s2; | ||
719 | return s1; | ||
720 | } | ||
721 | int main() | ||
722 | { | ||
723 | string s1 = "Hello"; | ||
724 | cout << fuck(s1, ", World!\n") << endl; | ||
725 | return 0; | ||
726 | }</code></pre> | ||
727 | <p>程序可以接受将 C-风格字符串赋值给<kbd>string&</kbd>。</p> | ||
728 | <p>首先,<kbd>string</kbd>类定义了<kbd>char*</kbd>到<kbd>string</kbd>的转换,因而可以使用字符数组初始化字符串;</p> | ||
729 | <p>其次,类型为 const | ||
730 | 引用的形参有一个属性:<strong>在形参与实参不匹配但可以转换的时候,程序会创建临时变量进行匹配,然后传参过去。</strong>换言之,程序调用之前创建一个临时<kbd>string</kbd>,把引用传递过去。 | ||
731 | </p> | ||
732 | <h3 id="对象继承和引用">对象、继承和引用</h3> | ||
733 | <p><strong>使得能将特性从一个类传递给另一个类的语言特性称为继承。</strong>继承的另一个特性是,基类引用可以指向派生类对象而无需进行强制转换。这种特性的实际结果为,派生类中可以定义一个以基类引用为参数的函数,调用该函数时,既能以基类为参数,也可以派生类为参数。 | ||
734 | </p> | ||
735 | <p>以<kbd>ofstream</kbd>与<kbd>ostream</kbd>为例,前者为派生类,后者为基类,因为前者建立在后者基础之上。派生类继承了基类的方法,这意味着<kbd>ofstream</kbd>可以使用<kbd>ostream</kbd>的特性,如格式化方法和输出运算符;参数类型为<kbd>ostream&</kbd>的函数既可以接收<kbd>ostream</kbd>对象(如 | ||
736 | cout),也可以接收已经声明的<kbd>ofstream</kbd>对象为参数。</p> | ||
737 | <h3 id="何时使用引用">何时使用引用</h3> | ||
738 | <p>使用引用参数的原因:</p> | ||
739 | <ul> | ||
740 | <li>能修改调用函数的数据对象</li> | ||
741 | <li>通过传递引用而非整个数据对象,提高运行速度。</li> | ||
742 | </ul> | ||
743 | <p>当数据对象较大(如结构体、类对象),第二个因素占主要,这也是使用指针的原因,因为引用实际上是指针的另一个接口。</p> | ||
744 | <p>什么时候使用指针、什么时候使用按值传递呢? 对于使用传递的值而不作修改的:</p> | ||
745 | <ul> | ||
746 | <li>数据量小,按值传递</li> | ||
747 | <li>是数组,指针传递,这是唯一办法,并将指针声明为指向 const 的指针</li> | ||
748 | <li>数据对象是较大的结构体,使用 const 引用或 const 指针</li> | ||
749 | <li>是类对象,使用 const 引用</li> | ||
750 | </ul> | ||
751 | <p>对于修改调用函数数据的函数:</p> | ||
752 | <ul> | ||
753 | <li>修改的是内置数据类型,使用指针</li> | ||
754 | <li>是数组,就只能用指针</li> | ||
755 | <li>是结构体,用指针或引用</li> | ||
756 | <li>是类对象,用引用</li> | ||
757 | </ul> | ||
758 | <h2 id="函数多态">函数多态</h2> | ||
759 | <p>函数多态是 C++在 C 基础上增加的功能。</p> | ||
760 | <ul> | ||
761 | <li>默认参数允许以不同数目的参数调用同一函数</li> | ||
762 | <li>重载允许使用多个同名的函数。</li> | ||
763 | </ul> | ||
764 | <h3 id="默认参数">默认参数</h3> | ||
765 | <p>默认参数指函数调用中省略实参时自动使用的实参值。</p> | ||
766 | <pre><code>// 一个使用默认参数的例子 | ||
767 | #include <iostream> | ||
768 | using namespace std; | ||
769 | int add(int a, int b = 1, int c = 2) | ||
770 | { | ||
771 | return a + b + c; | ||
772 | } | ||
773 | int main() | ||
774 | { | ||
775 | cout << add(5) << endl; // 8 | ||
776 | cout << add(5, 6) << endl; // 13 | ||
777 | cout << add(5, 6, 7) << endl; // 18 | ||
778 | return 0; | ||
779 | }</code></pre> | ||
780 | <p><strong>对于带参数列表(有形参)的函数,必须从右向左添加默认值,即所有有默认值的形参必须在所有无默认值形参的右边。使用时,传递的实参被从左到右依次赋给形参,而不得跳过任何形参。</strong></p> | ||
781 | <h3 id="函数重载">函数重载</h3> | ||
782 | <p>函数重载指可以有多个同名函数,它们<strong>以参数列表(形参,不包括返回值类型)为区别</strong>。C++使用上下文来确定要使用的重载函数版本。</p> | ||
783 | <pre><code>//一个函数重载示例程序 | ||
784 | #include <iostream> | ||
785 | using namespace std; | ||
786 | |||
787 | int add(int a, int b) | ||
788 | { | ||
789 | return a + b; | ||
790 | } | ||
791 | |||
792 | double add(double a, double b) | ||
793 | { | ||
794 | return a + b; | ||
795 | } | ||
796 | |||
797 | int main() | ||
798 | { | ||
799 | cout << add(1, 2) << endl; | ||
800 | cout << add(1.1, 2.2) << endl; | ||
801 | return 0; | ||
802 | }</code></pre> | ||
803 | <blockquote> | ||
804 | <p>仅当在函数执行基本相同的任务而使用不同的数据类型时,才适合重载</p> | ||
805 | <p>重载虽好,可不要贪杯哦~</p> | ||
806 | </blockquote> | ||
807 | <h2 id="函数模板">函数模板</h2> | ||
808 | <p>函数模板是通用的函数描述,使用泛型来定义函数,其中的泛型可用于指定的具体类型(即<kbd>int</kbd>/<kbd>double</kbd>等)替换。通过将类型作为参数传递给模板,可使编译器生成该类型的函数。 | ||
809 | </p> | ||
810 | <blockquote> | ||
811 | <p>少扯淡,一个代码就明白了</p> | ||
812 | </blockquote> | ||
813 | <pre><code>//一个使用函数模板的历次 | ||
814 | #include <iostream> | ||
815 | using namespace std; | ||
816 | |||
817 | template <typename T> | ||
818 | T max5(T a[]) | ||
819 | { | ||
820 | T max = a[0]; | ||
821 | for (int i = 1; i < 5; i++) | ||
822 | if (a[i] > max) | ||
823 | max = a[i]; | ||
824 | return max; | ||
825 | } | ||
826 | |||
827 | int main() | ||
828 | { | ||
829 | int a[5] = {1, 2, 3, 4, 5}; | ||
830 | double b[5] = {1.1, 2.2, 3.3, 4.4, 5.5}; | ||
831 | cout << max5(a) << endl; | ||
832 | cout << max5(b) << endl; | ||
833 | return 0; | ||
834 | }</code></pre> | ||
835 | <p>第一行指出,要建立一个模板,类型命名为 | ||
836 | T。关键字<kbd>template</kbd>和<kbd>typename</kbd>是必须的,但可以使用关键字<kbd>class</kbd>替代<kbd>typename</kbd>>。另外,必须使用尖括号。类型名可以随意写。 | ||
837 | </p> | ||
838 | <p>函数模板本身并不创建任何函数,只是告知编译器如何定义函数,由编译器探明和处理,各自按照模板新建一个函数。因而,函数模板不能缩短可执行程序,在上例中最终仍然是两个独立函数,并无函数模板。但模板的好处在于使生成多个同类型函数更简单可靠。 | ||
839 | </p> | ||
840 | <p>常见用法为<strong>将模板放在头文件中,在需要使用的地方包含头文件</strong>。</p> | ||
841 | <h3 id="模板重载">模板重载</h3> | ||
842 | <p>模板满足了对不同类型使用同一种算法函数的需求,但并非所有类型都是用完全相同的算法。为满足此种需求,可以像重载常规函数一样重载模板定义,仍然需要满足参数列表不同便是了。</p> | ||
843 | <pre><code>template<class T>//一个模板 | ||
844 | void swap(T &a,T &b); | ||
845 | |||
846 | template<class T>//另一个模板 | ||
847 | void swap(T* a,T* b,int n);</code></pre> | ||
848 | <h3 id="模板的局限性">模板的局限性</h3> | ||
849 | <p>模板局限性在于很可能无法处理某些数据类型。如赋值,一般类型赋值直接赋值即可,但数组则不可以;比较大小,一般数据类型可以直接比较,结构体则不行。</p> | ||
850 | <h3 id="具体化与实例化">具体化与实例化</h3> | ||
851 | <p><strong>又是什么 JB 东西,似乎有用但似乎用处不大,先放着吧。</strong></p> | ||
852 | <h3 id="编译器选择哪个函数版本">编译器选择哪个函数版本</h3> | ||
853 | <p>对于函数重载、函数模板和函数模板重载,C++需要一个定义良好的解析策略来确认调用哪一个函数定义,尤其是有多个参数的时候。此过程称为重载解析。</p> | ||
854 | <ul> | ||
855 | <li>创建候选函数列表,包含所有与被调用函数同名的函数与模板</li> | ||
856 | <li>使用候选函数列表,根据实参来创建可行函数列表</li> | ||
857 | <li>确定是否有最佳的可行函数,有则使用,无则报错。优先级如下: | ||
858 | <ul> | ||
859 | <li>完全匹配,但<strong>常规函数优先于模板</strong></li> | ||
860 | <li>提升转换(<kbd>char</kbd>/<kbd>chort</kbd>–><kbd>int</kbd>,<kbd>float</kbd>–><kbd>double</kbd>) | ||
861 | </li> | ||
862 | <li>标准转换(<kbd>int</kbd>–><kbd>char</kbd>,<kbd>long</kbd>–><kbd>double</kbd>)</li> | ||
863 | <li>用户定义的转换,如类声明中定义的转换。</li> | ||
864 | </ul> | ||
865 | </li> | ||
866 | </ul> | ||
867 | <blockquote> | ||
868 | <p>完全匹配时,允许某些无关紧要的转换,如下表。</p> | ||
869 | <table> | ||
870 | <thead> | ||
871 | <tr class="header"> | ||
872 | <th>实参</th> | ||
873 | <th>形参</th> | ||
874 | </tr> | ||
875 | </thead> | ||
876 | <tbody> | ||
877 | <tr class="odd"> | ||
878 | <td>Type</td> | ||
879 | <td>Type&</td> | ||
880 | </tr> | ||
881 | <tr class="even"> | ||
882 | <td>Type&</td> | ||
883 | <td>Type</td> | ||
884 | </tr> | ||
885 | <tr class="odd"> | ||
886 | <td>Type[]</td> | ||
887 | <td>*Type</td> | ||
888 | </tr> | ||
889 | <tr class="even"> | ||
890 | <td>Type(argument0list)</td> | ||
891 | <td>Type(*)(argument-list)</td> | ||
892 | </tr> | ||
893 | <tr class="odd"> | ||
894 | <td>Type</td> | ||
895 | <td>const Type</td> | ||
896 | </tr> | ||
897 | <tr class="even"> | ||
898 | <td>Type</td> | ||
899 | <td>volatile Type</td> | ||
900 | </tr> | ||
901 | <tr class="odd"> | ||
902 | <td>Type*</td> | ||
903 | <td>const Type</td> | ||
904 | </tr> | ||
905 | <tr class="even"> | ||
906 | <td>Type*</td> | ||
907 | <td>volatile Type</td> | ||
908 | </tr> | ||
909 | </tbody> | ||
910 | </table> | ||
911 | </blockquote> | ||
912 | <pre><code>//调用函数 | ||
913 | may('B'); | ||
914 | |||
915 | //所有同名 | ||
916 | void may(int); // 1 | ||
917 | float may(float, float = 3); // 2 | ||
918 | void may(char); // 3 | ||
919 | char *may(const char *); // 4 | ||
920 | char may(const char &); // 5 | ||
921 | |||
922 | template <class T> | ||
923 | void may(const T &); // 6 | ||
924 | |||
925 | template <class T> | ||
926 | void may(T *); // 7</code></pre> | ||
927 | <p>由上述规则可以看出,优先级情况如下:</p> | ||
928 | <ul> | ||
929 | <li>完全匹配:3、5、6</li> | ||
930 | <li>提升转换:1</li> | ||
931 | <li>标准转换:2</li> | ||
932 | <li>不符合:4、7</li> | ||
933 | </ul> | ||
934 | <p>其中,3、5 是常规函数,优先级高于 6 模板。</p> | ||
935 | <p>有两个最佳选择的情况一般认为是错误的,但有特例。</p> | ||
936 | <ul> | ||
937 | <li>指向非 const 数据的指针和引用优先与非 const 指针和引用参数匹配,反之然</li> | ||
938 | <li>其中一个是非模板函数而另一个不是,此时废模板函数优先于模板函数(包括显式具体化)</li> | ||
939 | </ul> | ||
940 | <h1 id="文件操作">文件操作</h1> | ||
941 | <h2 id="头文件">头文件</h2> | ||
942 | <p>C++文件操作头文件 fstream,也就是“文件流”。</p> | ||
943 | <h2 id="对象声明">对象声明</h2> | ||
944 | <pre><code>ofstream ofs;//执行写操作 | ||
945 | ifstream ifs;//执行读操作 | ||
946 | fstream file;//读写都可以</code></pre> | ||
947 | <h2 id="文件打开关闭">文件打开、关闭</h2> | ||
948 | <p>以下所有内容均假设使用对象名为 file(不论是 ofstream 还是 ifstream/fstream),打开方式为:<code>file.open(文件路径,打开方式);</code> | ||
949 | 同时也可以在定义流对象时直接打开: <code>ifstream file(文件路径,打开方式)</code> 其中,文件路径的参数为 string 类型字符串或 char*型字符数组。</p> | ||
950 | <table> | ||
951 | <thead> | ||
952 | <tr class="header"> | ||
953 | <th style="text-align: center;">打开方式</th> | ||
954 | <th style="text-align: center;">解释</th> | ||
955 | </tr> | ||
956 | </thead> | ||
957 | <tbody> | ||
958 | <tr class="odd"> | ||
959 | <td style="text-align: center;">ios::in</td> | ||
960 | <td style="text-align: center;">读取</td> | ||
961 | </tr> | ||
962 | <tr class="even"> | ||
963 | <td style="text-align: center;">ios::out</td> | ||
964 | <td style="text-align: center;">写入</td> | ||
965 | </tr> | ||
966 | <tr class="odd"> | ||
967 | <td style="text-align: center;">ios::ate</td> | ||
968 | <td style="text-align: center;">初始位置:文件尾</td> | ||
969 | </tr> | ||
970 | <tr class="even"> | ||
971 | <td style="text-align: center;">ios::app</td> | ||
972 | <td style="text-align: center;">追加方式写文件</td> | ||
973 | </tr> | ||
974 | <tr class="odd"> | ||
975 | <td style="text-align: center;">ios::trunc</td> | ||
976 | <td style="text-align: center;">如果文件存在先删除,再创建</td> | ||
977 | </tr> | ||
978 | <tr class="even"> | ||
979 | <td style="text-align: center;">ios::binary</td> | ||
980 | <td style="text-align: center;">二进制方式</td> | ||
981 | </tr> | ||
982 | </tbody> | ||
983 | </table> | ||
984 | <p>文件关闭:<code>file.close();</code> | ||
985 | 文件关闭之后流并未删除,只是断开了流到文件的链接,流管理装置仍然保留,因而可以用来再次打开某个文件。此时由于之前使用的内容还储存着,为避免对之后的使用造成影响,应当在文件关闭后使用函数<code>file.clear()</code>把整个类全部重置。 | ||
986 | </p> | ||
987 | <ul> | ||
988 | <li>注意:文件打开方式可以配合使用,利用 | 操作符。例如,用二进制方式写文件: <code>ios::out | ios::binary</code></li> | ||
989 | <li>ios 即 basic_ios,二者互为别名;ios 类是在 ios_base 基础上的派生类。</li> | ||
990 | <li>打开方式可以不写,默认打开方式为<code>ios::in|ios::out</code>,以默认模式打开文件进行输出(写入)时,文件长度将自动截短为 0,也就是删除之前内容。</li> | ||
991 | </ul> | ||
992 | <h2 id="文件操作-1">文件操作</h2> | ||
993 | <ul> | ||
994 | <li>由于<code>ifstream</code>、<code>ofstream</code>、<code>fstream</code>等<code>fstream</code>中定义的类都是从<code>iostream</code>的相应类中派生而来,所以均可使用原来的类的操作方法,并且继承其特性(如 | ||
995 | ifs 会和 cin 一样,遇到空格就截断字符串)。一如 C 语言中的 gets/fgets、scanf/fscanf、printf/fprintf。</li> | ||
996 | </ul> | ||
997 | <h2 id="文本文件">文本文件</h2> | ||
998 | <h3 id="读取">读取</h3> | ||
999 | <p>五种方法。例程如下:</p> | ||
1000 | <pre><code>#include <iostream> | ||
1001 | #include <string> | ||
1002 | #include <fstream> | ||
1003 | using namespace std; | ||
1004 | |||
1005 | int main() | ||
1006 | { | ||
1007 | ifstream ifs; | ||
1008 | char buf[1000] = { 0 }; | ||
1009 | string s; | ||
1010 | ifs.open("test.txt",ios::in); | ||
1011 | if(!ifs.is_open()) | ||
1012 | { | ||
1013 | cout << "文件打开失败!" << endl; | ||
1014 | return -1; | ||
1015 | } | ||
1016 | /*方法一,缺点在于空格即断开*/ | ||
1017 | while(ifs >> buf) | ||
1018 | { | ||
1019 | cout << buf <<endl; | ||
1020 | } | ||
1021 | /*方法二,缺点同上*/ | ||
1022 | while(ifs.getline(buf,sizeof(buf))) | ||
1023 | { | ||
1024 | cout << buf <<endl; | ||
1025 | } | ||
1026 | /*方法三,整行读取*/ | ||
1027 | while(getline(ifs,s)) | ||
1028 | { | ||
1029 | cout << buf <<endl; | ||
1030 | } | ||
1031 | /*方法四,逐个字符读取,太不爽*/ | ||
1032 | char c; | ||
1033 | while((c = ifs.get()) != EOF) | ||
1034 | { | ||
1035 | cout<<c; | ||
1036 | } | ||
1037 | /*方法五,缺点在和cin一样,遇到空格就截断,而不只是换行符*/ | ||
1038 | ifs >> buf; | ||
1039 | |||
1040 | ifs.close(); | ||
1041 | ifs.clear(); | ||
1042 | return 0; | ||
1043 | }</code></pre> | ||
1044 | <h3 id="文件写入">文件写入</h3> | ||
1045 | <p>格式如下: <code>对象名 << 写入的内容;</code> 如需换行,在写入内容后加 endl 即可。例程如下:</p> | ||
1046 | <pre><code>#include <iostream> | ||
1047 | #include <string> | ||
1048 | #include <fstream> | ||
1049 | using namespace std; | ||
1050 | |||
1051 | int main() | ||
1052 | { | ||
1053 | ofstream ofs; | ||
1054 | ofs.open("test.txt",ios::out); | ||
1055 | if(!ofs.is_open()) | ||
1056 | { | ||
1057 | cout << "文件打开失败!" << endl; | ||
1058 | return -1; | ||
1059 | } | ||
1060 | ofs << "-How old are you?" << endl; | ||
1061 | ofs << "-I'm 21ys old." << endl; | ||
1062 | ofs << "-Oh,what a young guy!" << endl; | ||
1063 | ofs << "-Thanks." <<endl; | ||
1064 | ofs.close(); | ||
1065 | return 0; | ||
1066 | }</code></pre> | ||
1067 | <h3 id="总结">总结</h3> | ||
1068 | <p>读文件可以利用 ifstream 或者 fstream 类。 利用 is_open 函数可以判断文件是否打开成功。 操作完毕,要关闭文件。</p> | ||
1069 | <h2 id="二进制文件">二进制文件</h2> | ||
1070 | <p>以二进制形式读写文件。 打开方式需要指定为<code>ios::binary</code>。</p> | ||
1071 | <h3 id="读取-1">读取</h3> | ||
1072 | <p>利用流对象调用成员函数<code>read</code>。 函数原型:<code>istream& read(char* buffer, int len)</code> 参数解释:字符指针 buffer | ||
1073 | 指向内存中一段存储空间。len 是读写的字节数。 例程如下:</p> | ||
1074 | <pre><code>#include <iostream> | ||
1075 | #include <string> | ||
1076 | #include <fstream> | ||
1077 | using namespace std; | ||
1078 | |||
1079 | int main() | ||
1080 | { | ||
1081 | ifstream ifs; | ||
1082 | int a[10]; | ||
1083 | ifs.open("test.bin",ios::in | ios::binary); | ||
1084 | if(!ifs.is_open()) | ||
1085 | { | ||
1086 | cout << "文件打开失败!" << endl; | ||
1087 | return -1; | ||
1088 | } | ||
1089 | ifs.read((char*)a, sizeof(int) * 10); | ||
1090 | return 0; | ||
1091 | }</code></pre> | ||
1092 | <h3 id="写入">写入</h3> | ||
1093 | <p>使用流对象成员函数<code>write</code>。 函数原型:<code>ostream& write(const char* buffer, int len)</code> 参数解释:字符指针 | ||
1094 | buffer 指向内存中一段存储空间。len 是读写的字节数。 例程如下:</p> | ||
1095 | <pre><code>#include <iostream> | ||
1096 | #include <string> | ||
1097 | #include <fstream> | ||
1098 | using namespace std; | ||
1099 | |||
1100 | int main() | ||
1101 | { | ||
1102 | ofstream ofs; | ||
1103 | int c=-3; | ||
1104 | string s="Long Live the People!"; | ||
1105 | ifs.open("test.bin",ios::in | ios::binary); | ||
1106 | if(!ofs.is_open()) | ||
1107 | { | ||
1108 | cout << "文件打开失败!" << endl; | ||
1109 | return -1; | ||
1110 | } | ||
1111 | ofs.read((char*)&c,sizeof(c)); | ||
1112 | ofs.read(s.c_str(),sizeof(char) * s.length()); | ||
1113 | return 0; | ||
1114 | }</code></pre> | ||
62 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | 1115 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> |
63 | </div> | 1116 | </div> |
64 | </div> | 1117 | </div> |
65 | |||
66 | </body> | 1118 | </body> |
67 | 1119 | ||
68 | </html> \ No newline at end of file | 1120 | </html> \ No newline at end of file |
diff --git a/code/cpppp.md b/code/cpppp.md index 9c55900..50f5cba 100644 --- a/code/cpppp.md +++ b/code/cpppp.md | |||
@@ -1,5 +1,3 @@ | |||
1 | [toc] | ||
2 | |||
3 | # 第二章 | 1 | # 第二章 |
4 | 2 | ||
5 | - 在 C++中,$main$函数括号中使用`void`关键字表明拒绝任何参数,而空括号表示对是否接受参数保持沉默。 | 3 | - 在 C++中,$main$函数括号中使用`void`关键字表明拒绝任何参数,而空括号表示对是否接受参数保持沉默。 |
@@ -974,3 +972,197 @@ void may(T *); // 7 | |||
974 | 972 | ||
975 | - 指向非 const 数据的指针和引用优先与非 const 指针和引用参数匹配,反之然 | 973 | - 指向非 const 数据的指针和引用优先与非 const 指针和引用参数匹配,反之然 |
976 | - 其中一个是非模板函数而另一个不是,此时废模板函数优先于模板函数(包括显式具体化) | 974 | - 其中一个是非模板函数而另一个不是,此时废模板函数优先于模板函数(包括显式具体化) |
975 | |||
976 | # 文件操作 | ||
977 | |||
978 | ## 头文件 | ||
979 | |||
980 | C++文件操作头文件 fstream,也就是“文件流”。 | ||
981 | |||
982 | ## 对象声明 | ||
983 | |||
984 | ```C++ | ||
985 | ofstream ofs;//执行写操作 | ||
986 | ifstream ifs;//执行读操作 | ||
987 | fstream file;//读写都可以 | ||
988 | ``` | ||
989 | |||
990 | ## 文件打开、关闭 | ||
991 | |||
992 | 以下所有内容均假设使用对象名为 file(不论是 ofstream 还是 ifstream/fstream),打开方式为:`file.open(文件路径,打开方式);` | ||
993 | 同时也可以在定义流对象时直接打开: | ||
994 | `ifstream file(文件路径,打开方式)` | ||
995 | 其中,文件路径的参数为 string 类型字符串或 char\*型字符数组。 | ||
996 | |||
997 | | 打开方式 | 解释 | | ||
998 | | :---------: | :------------------------: | | ||
999 | | ios::in | 读取 | | ||
1000 | | ios::out | 写入 | | ||
1001 | | ios::ate | 初始位置:文件尾 | | ||
1002 | | ios::app | 追加方式写文件 | | ||
1003 | | ios::trunc | 如果文件存在先删除,再创建 | | ||
1004 | | ios::binary | 二进制方式 | | ||
1005 | |||
1006 | 文件关闭:`file.close();` | ||
1007 | 文件关闭之后流并未删除,只是断开了流到文件的链接,流管理装置仍然保留,因而可以用来再次打开某个文件。此时由于之前使用的内容还储存着,为避免对之后的使用造成影响,应当在文件关闭后使用函数`file.clear()`把整个类全部重置。 | ||
1008 | |||
1009 | - 注意:文件打开方式可以配合使用,利用 | 操作符。例如,用二进制方式写文件: | ||
1010 | `ios::out | ios::binary` | ||
1011 | - ios 即 basic_ios,二者互为别名;ios 类是在 ios_base 基础上的派生类。 | ||
1012 | - 打开方式可以不写,默认打开方式为`ios::in|ios::out`,以默认模式打开文件进行输出(写入)时,文件长度将自动截短为 0,也就是删除之前内容。 | ||
1013 | |||
1014 | ## 文件操作 | ||
1015 | |||
1016 | - 由于`ifstream`、`ofstream`、`fstream`等`fstream`中定义的类都是从`iostream`的相应类中派生而来,所以均可使用原来的类的操作方法,并且继承其特性(如 ifs 会和 cin 一样,遇到空格就截断字符串)。一如 C 语言中的 gets/fgets、scanf/fscanf、printf/fprintf。 | ||
1017 | |||
1018 | ## 文本文件 | ||
1019 | |||
1020 | ### 读取 | ||
1021 | |||
1022 | 五种方法。例程如下: | ||
1023 | |||
1024 | ```C++ | ||
1025 | #include <iostream> | ||
1026 | #include <string> | ||
1027 | #include <fstream> | ||
1028 | using namespace std; | ||
1029 | |||
1030 | int main() | ||
1031 | { | ||
1032 | ifstream ifs; | ||
1033 | char buf[1000] = { 0 }; | ||
1034 | string s; | ||
1035 | ifs.open("test.txt",ios::in); | ||
1036 | if(!ifs.is_open()) | ||
1037 | { | ||
1038 | cout << "文件打开失败!" << endl; | ||
1039 | return -1; | ||
1040 | } | ||
1041 | /*方法一,缺点在于空格即断开*/ | ||
1042 | while(ifs >> buf) | ||
1043 | { | ||
1044 | cout << buf <<endl; | ||
1045 | } | ||
1046 | /*方法二,缺点同上*/ | ||
1047 | while(ifs.getline(buf,sizeof(buf))) | ||
1048 | { | ||
1049 | cout << buf <<endl; | ||
1050 | } | ||
1051 | /*方法三,整行读取*/ | ||
1052 | while(getline(ifs,s)) | ||
1053 | { | ||
1054 | cout << buf <<endl; | ||
1055 | } | ||
1056 | /*方法四,逐个字符读取,太不爽*/ | ||
1057 | char c; | ||
1058 | while((c = ifs.get()) != EOF) | ||
1059 | { | ||
1060 | cout<<c; | ||
1061 | } | ||
1062 | /*方法五,缺点在和cin一样,遇到空格就截断,而不只是换行符*/ | ||
1063 | ifs >> buf; | ||
1064 | |||
1065 | ifs.close(); | ||
1066 | ifs.clear(); | ||
1067 | return 0; | ||
1068 | } | ||
1069 | ``` | ||
1070 | |||
1071 | ### 文件写入 | ||
1072 | |||
1073 | 格式如下: | ||
1074 | `对象名 << 写入的内容;` | ||
1075 | 如需换行,在写入内容后加 endl 即可。例程如下: | ||
1076 | |||
1077 | ```C++ | ||
1078 | #include <iostream> | ||
1079 | #include <string> | ||
1080 | #include <fstream> | ||
1081 | using namespace std; | ||
1082 | |||
1083 | int main() | ||
1084 | { | ||
1085 | ofstream ofs; | ||
1086 | ofs.open("test.txt",ios::out); | ||
1087 | if(!ofs.is_open()) | ||
1088 | { | ||
1089 | cout << "文件打开失败!" << endl; | ||
1090 | return -1; | ||
1091 | } | ||
1092 | ofs << "-How old are you?" << endl; | ||
1093 | ofs << "-I'm 21ys old." << endl; | ||
1094 | ofs << "-Oh,what a young guy!" << endl; | ||
1095 | ofs << "-Thanks." <<endl; | ||
1096 | ofs.close(); | ||
1097 | return 0; | ||
1098 | } | ||
1099 | ``` | ||
1100 | |||
1101 | ### 总结 | ||
1102 | |||
1103 | 读文件可以利用 ifstream 或者 fstream 类。 | ||
1104 | 利用 is_open 函数可以判断文件是否打开成功。 | ||
1105 | 操作完毕,要关闭文件。 | ||
1106 | |||
1107 | ## 二进制文件 | ||
1108 | |||
1109 | 以二进制形式读写文件。 | ||
1110 | 打开方式需要指定为`ios::binary`。 | ||
1111 | |||
1112 | ### 读取 | ||
1113 | |||
1114 | 利用流对象调用成员函数`read`。 | ||
1115 | 函数原型:`istream& read(char* buffer, int len)` | ||
1116 | 参数解释:字符指针 buffer 指向内存中一段存储空间。len 是读写的字节数。 | ||
1117 | 例程如下: | ||
1118 | |||
1119 | ```c++ | ||
1120 | #include <iostream> | ||
1121 | #include <string> | ||
1122 | #include <fstream> | ||
1123 | using namespace std; | ||
1124 | |||
1125 | int main() | ||
1126 | { | ||
1127 | ifstream ifs; | ||
1128 | int a[10]; | ||
1129 | ifs.open("test.bin",ios::in | ios::binary); | ||
1130 | if(!ifs.is_open()) | ||
1131 | { | ||
1132 | cout << "文件打开失败!" << endl; | ||
1133 | return -1; | ||
1134 | } | ||
1135 | ifs.read((char*)a, sizeof(int) * 10); | ||
1136 | return 0; | ||
1137 | } | ||
1138 | ``` | ||
1139 | |||
1140 | ### 写入 | ||
1141 | |||
1142 | 使用流对象成员函数`write`。 | ||
1143 | 函数原型:`ostream& write(const char* buffer, int len)` | ||
1144 | 参数解释:字符指针 buffer 指向内存中一段存储空间。len 是读写的字节数。 | ||
1145 | 例程如下: | ||
1146 | |||
1147 | ```c++ | ||
1148 | #include <iostream> | ||
1149 | #include <string> | ||
1150 | #include <fstream> | ||
1151 | using namespace std; | ||
1152 | |||
1153 | int main() | ||
1154 | { | ||
1155 | ofstream ofs; | ||
1156 | int c=-3; | ||
1157 | string s="Long Live the People!"; | ||
1158 | ifs.open("test.bin",ios::in | ios::binary); | ||
1159 | if(!ofs.is_open()) | ||
1160 | { | ||
1161 | cout << "文件打开失败!" << endl; | ||
1162 | return -1; | ||
1163 | } | ||
1164 | ofs.read((char*)&c,sizeof(c)); | ||
1165 | ofs.read(s.c_str(),sizeof(char) * s.length()); | ||
1166 | return 0; | ||
1167 | } | ||
1168 | ``` | ||
diff --git a/code/experiment/index.html b/code/experiment.html index a3f0b5a..e573094 100644 --- a/code/experiment/index.html +++ b/code/experiment.html | |||
@@ -4,27 +4,31 @@ | |||
4 | <head> | 4 | <head> |
5 | <meta charset='UTF-8'> | 5 | <meta charset='UTF-8'> |
6 | <meta name='viewport' content='width=device-width initial-scale=1'> | 6 | <meta name='viewport' content='width=device-width initial-scale=1'> |
7 | <title>Matlab</title> | 7 | <title>大物实验Matlab</title> |
8 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/style.css"> | 8 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/github.css"> |
9 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 9 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
10 | </head> | 10 | </head> |
11 | 11 | ||
12 | <body class='typora-export os-windows'> | 12 | <body class='typora-export os-windows'> |
13 | <div class='typora-export-content'> | 13 | <div class='typora-export-content'> |
14 | <div id='write' class=''> | 14 | <div id='write' class=''> |
15 | <p class="title">大物实验Matlab</p> | ||
15 | <div class='md-toc' mdtype='toc'> | 16 | <div class='md-toc' mdtype='toc'> |
16 | <p class="md-toc-content" role="list"><span role="listitem" class="md-toc-item md-toc-h1" | 17 | <p class="md-toc-content" role="list"><span role="listitem" class="md-toc-item md-toc-h1" |
17 | data-ref="n123"><a class="md-toc-inner" href="#前言">前言</a></span><span role="listitem" | 18 | data-ref="n123"><a class="md-toc-inner" href="#前言">前言</a></span><span role="listitem" |
18 | class="md-toc-item md-toc-h1" data-ref="n142"><a class="md-toc-inner" | 19 | class="md-toc-item md-toc-h1" data-ref="n142"><a class="md-toc-inner" |
19 | href="#工具">工具</a></span><span role="listitem" class="md-toc-item md-toc-h1" | 20 | href="#工具">工具</a></span><span role="listitem" class="md-toc-item md-toc-h1" |
20 | data-ref="n146"><a class="md-toc-inner" href="#代码">代码</a></span><span role="listitem" | 21 | data-ref="n146"><a class="md-toc-inner" href="#代码">代码</a></span><span role="listitem" |
21 | class="md-toc-item md-toc-h2" data-ref="n147"><a class="md-toc-inner" href="#lab1-碰撞打靶实验">Lab1 碰撞打靶实验</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n149"><a | 22 | class="md-toc-item md-toc-h2" data-ref="n147"><a class="md-toc-inner" href="#lab1-碰撞打靶实验">Lab1 |
23 | 碰撞打靶实验</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n149"><a | ||
22 | class="md-toc-inner" href="#lab2-拉伸法测杨氏模量">Lab2 拉伸法测杨氏模量</a></span><span role="listitem" | 24 | class="md-toc-inner" href="#lab2-拉伸法测杨氏模量">Lab2 拉伸法测杨氏模量</a></span><span role="listitem" |
23 | class="md-toc-item md-toc-h2" data-ref="n151"><a class="md-toc-inner" href="#lab5-液体粘度测定">Lab5 液体粘度测定</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n153"><a | 25 | class="md-toc-item md-toc-h2" data-ref="n151"><a class="md-toc-inner" href="#lab5-液体粘度测定">Lab5 |
26 | 液体粘度测定</a></span><span role="listitem" class="md-toc-item md-toc-h2" data-ref="n153"><a | ||
24 | class="md-toc-inner" href="#lab10-线性和非线性元件伏安特性曲线测定">Lab10 线性和非线性元件伏安特性曲线测定</a></span><span | 27 | class="md-toc-inner" href="#lab10-线性和非线性元件伏安特性曲线测定">Lab10 线性和非线性元件伏安特性曲线测定</a></span><span |
25 | role="listitem" class="md-toc-item md-toc-h2" data-ref="n155"><a class="md-toc-inner" | 28 | role="listitem" class="md-toc-item md-toc-h2" data-ref="n155"><a class="md-toc-inner" |
26 | href="#lab13-示波器的原理和应用">Lab13 示波器的原理和应用</a></span><span role="listitem" | 29 | href="#lab13-示波器的原理和应用">Lab13 示波器的原理和应用</a></span><span role="listitem" |
27 | class="md-toc-item md-toc-h2" data-ref="n157"><a class="md-toc-inner" href="#lab22-光的等厚干涉">Lab22 光的等厚干涉</a></span></p> | 30 | class="md-toc-item md-toc-h2" data-ref="n157"><a class="md-toc-inner" href="#lab22-光的等厚干涉">Lab22 |
31 | 光的等厚干涉</a></span></p> | ||
28 | </div> | 32 | </div> |
29 | <h1 id='前言'><span>前言</span></h1> | 33 | <h1 id='前言'><span>前言</span></h1> |
30 | <blockquote> | 34 | <blockquote> |
@@ -32,14 +36,22 @@ | |||
32 | </blockquote> | 36 | </blockquote> |
33 | <p><span>本人没少受<strong>各位CSDN大佬、窝工网盘计划各位前辈</strong>的恩惠,也想给后来者留点东西。把自己做的几个大物实验的图像处理和数据计算的代码留下吧,万一有人用了呢?</span> | 37 | <p><span>本人没少受<strong>各位CSDN大佬、窝工网盘计划各位前辈</strong>的恩惠,也想给后来者留点东西。把自己做的几个大物实验的图像处理和数据计算的代码留下吧,万一有人用了呢?</span> |
34 | <br><strong>注意:</strong> | 38 | <br><strong>注意:</strong> |
35 | <ul> | 39 | <ul> |
36 | <li>本文所有代码带的数据都是本人实验数据,自己用的时候记得</n><strong>改成自己的数据。</strong><ul><li>大部分原始数据我都写在了<strong>代码开头部分</strong>,也试图尽力让变量名尽量可辨识。</li></ul></li> | 40 | <li>本文所有代码带的数据都是本人实验数据,自己用的时候记得</n><strong>改成自己的数据。</strong> |
41 | <ul> | ||
42 | <li>大部分原始数据我都写在了<strong>代码开头部分</strong>,也试图尽力让变量名尽量可辨识。</li> | ||
43 | </ul> | ||
44 | </li> | ||
37 | 45 | ||
38 | <li>本文代码可能不完全正确,但都是我用过了的,<strong>基本还是错不了。</strong><ul><li>如发现确有问题,评论留言,我改一下,以免贻误后来人。</li></ul></li> | 46 | <li>本文代码可能不完全正确,但都是我用过了的,<strong>基本还是错不了。</strong> |
47 | <ul> | ||
48 | <li>如发现确有问题,评论留言,我改一下,以免贻误后来人。</li> | ||
49 | </ul> | ||
50 | </li> | ||
39 | 51 | ||
40 | <li>使用过程中如果出现展示数据是1.49999999999这样的,不用怀疑,就是<strong>计算机存储的数据精度问题</strong>,其实计算结果就是1.50。</li> | 52 | <li>使用过程中如果出现展示数据是1.49999999999这样的,不用怀疑,就是<strong>计算机存储的数据精度问题</strong>,其实计算结果就是1.50。</li> |
41 | <li>这些计算结果很有可能</span><strong><span>保留位数不对</span></strong><span>,记得按照实验数据的有效数字自己手动保留哈~</li> | 53 | <li>这些计算结果很有可能</span><strong><span>保留位数不对</span></strong><span>,记得按照实验数据的有效数字自己手动保留哈~</li> |
42 | </ul> | 54 | </ul> |
43 | </p> | 55 | </p> |
44 | <h1 id='工具'><span>工具</span></h1> | 56 | <h1 id='工具'><span>工具</span></h1> |
45 | <p><span>本文使用的工具为</span><strong><span>MATLAB R2022a</span></strong><span>。</span></p> | 57 | <p><span>本文使用的工具为</span><strong><span>MATLAB R2022a</span></strong><span>。</span></p> |
@@ -91,8 +103,8 @@ | |||
91 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 103 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
92 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div> | 104 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div> |
93 | </div> | 105 | </div> |
94 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 106 | <pre class=" CodeMirror-line " |
95 | </span></span></pre> | 107 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
96 | </div> | 108 | </div> |
97 | <div style="position: relative;"> | 109 | <div style="position: relative;"> |
98 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 110 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -105,8 +117,8 @@ | |||
105 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 117 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
106 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div> | 118 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">9</div> |
107 | </div> | 119 | </div> |
108 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 120 | <pre class=" CodeMirror-line " |
109 | </span></span></pre> | 121 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
110 | </div> | 122 | </div> |
111 | <div style="position: relative;"> | 123 | <div style="position: relative;"> |
112 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 124 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -127,8 +139,8 @@ | |||
127 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 139 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
128 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div> | 140 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div> |
129 | </div> | 141 | </div> |
130 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 142 | <pre class=" CodeMirror-line " |
131 | </span></span></pre> | 143 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
132 | </div> | 144 | </div> |
133 | <div style="position: relative;"> | 145 | <div style="position: relative;"> |
134 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 146 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -169,8 +181,8 @@ | |||
169 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 181 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
170 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div> | 182 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">18</div> |
171 | </div> | 183 | </div> |
172 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 184 | <pre class=" CodeMirror-line " |
173 | </span></span></pre> | 185 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
174 | </div> | 186 | </div> |
175 | <div style="position: relative;"> | 187 | <div style="position: relative;"> |
176 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 188 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -191,8 +203,8 @@ | |||
191 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 203 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
192 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div> | 204 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div> |
193 | </div> | 205 | </div> |
194 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 206 | <pre class=" CodeMirror-line " |
195 | </span></span></pre> | 207 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
196 | </div> | 208 | </div> |
197 | <div style="position: relative;"> | 209 | <div style="position: relative;"> |
198 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 210 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -233,8 +245,8 @@ | |||
233 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 245 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
234 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">27</div> | 246 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">27</div> |
235 | </div> | 247 | </div> |
236 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 248 | <pre class=" CodeMirror-line " |
237 | </span></span></pre> | 249 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
238 | </div> | 250 | </div> |
239 | <div style="position: relative;"> | 251 | <div style="position: relative;"> |
240 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 252 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -247,8 +259,8 @@ | |||
247 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 259 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
248 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">29</div> | 260 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">29</div> |
249 | </div> | 261 | </div> |
250 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 262 | <pre class=" CodeMirror-line " |
251 | </span></span></pre> | 263 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
252 | </div> | 264 | </div> |
253 | <div style="position: relative;"> | 265 | <div style="position: relative;"> |
254 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 266 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -283,8 +295,8 @@ | |||
283 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 295 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
284 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">34</div> | 296 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">34</div> |
285 | </div> | 297 | </div> |
286 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 298 | <pre class=" CodeMirror-line " |
287 | </span></span></pre> | 299 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
288 | </div> | 300 | </div> |
289 | <div style="position: relative;"> | 301 | <div style="position: relative;"> |
290 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 302 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -326,8 +338,8 @@ | |||
326 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | 338 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" |
327 | style="left: 0px; width: 26px;">40</div> | 339 | style="left: 0px; width: 26px;">40</div> |
328 | </div> | 340 | </div> |
329 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 341 | <pre class=" CodeMirror-line " |
330 | </span></span></pre> | 342 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
331 | </div> | 343 | </div> |
332 | <div style="position: relative;"> | 344 | <div style="position: relative;"> |
333 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 345 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -471,8 +483,8 @@ | |||
471 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 483 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
472 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div> | 484 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">14</div> |
473 | </div> | 485 | </div> |
474 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 486 | <pre class=" CodeMirror-line " |
475 | </span></span></pre> | 487 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
476 | </div> | 488 | </div> |
477 | <div style="position: relative;"> | 489 | <div style="position: relative;"> |
478 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 490 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -544,8 +556,8 @@ | |||
544 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 556 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
545 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">24</div> | 557 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">24</div> |
546 | </div> | 558 | </div> |
547 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 559 | <pre class=" CodeMirror-line " |
548 | </span></span></pre> | 560 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
549 | </div> | 561 | </div> |
550 | <div style="position: relative;"> | 562 | <div style="position: relative;"> |
551 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 563 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -636,8 +648,8 @@ | |||
636 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 648 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
637 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">37</div> | 649 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">37</div> |
638 | </div> | 650 | </div> |
639 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 651 | <pre class=" CodeMirror-line " |
640 | </span></span></pre> | 652 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
641 | </div> | 653 | </div> |
642 | <div style="position: relative;"> | 654 | <div style="position: relative;"> |
643 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 655 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -714,8 +726,8 @@ | |||
714 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 726 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
715 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">48</div> | 727 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">48</div> |
716 | </div> | 728 | </div> |
717 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 729 | <pre class=" CodeMirror-line " |
718 | </span></span></pre> | 730 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
719 | </div> | 731 | </div> |
720 | <div style="position: relative;"> | 732 | <div style="position: relative;"> |
721 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 733 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -750,8 +762,8 @@ | |||
750 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 762 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
751 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">53</div> | 763 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">53</div> |
752 | </div> | 764 | </div> |
753 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 765 | <pre class=" CodeMirror-line " |
754 | </span></span></pre> | 766 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
755 | </div> | 767 | </div> |
756 | <div style="position: relative;"> | 768 | <div style="position: relative;"> |
757 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 769 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1001,15 +1013,15 @@ | |||
1001 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1013 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1002 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div> | 1014 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">11</div> |
1003 | </div> | 1015 | </div> |
1004 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1016 | <pre class=" CodeMirror-line " |
1005 | </span></span></pre> | 1017 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1006 | </div> | 1018 | </div> |
1007 | <div style="position: relative;"> | 1019 | <div style="position: relative;"> |
1008 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1020 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1009 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div> | 1021 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">12</div> |
1010 | </div> | 1022 | </div> |
1011 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1023 | <pre class=" CodeMirror-line " |
1012 | </span></span></pre> | 1024 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1013 | </div> | 1025 | </div> |
1014 | <div style="position: relative;"> | 1026 | <div style="position: relative;"> |
1015 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1027 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1079,8 +1091,8 @@ | |||
1079 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1091 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1080 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div> | 1092 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div> |
1081 | </div> | 1093 | </div> |
1082 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1094 | <pre class=" CodeMirror-line " |
1083 | </span></span></pre> | 1095 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1084 | </div> | 1096 | </div> |
1085 | <div style="position: relative;"> | 1097 | <div style="position: relative;"> |
1086 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1098 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1100,8 +1112,8 @@ | |||
1100 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1112 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1101 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">25</div> | 1113 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">25</div> |
1102 | </div> | 1114 | </div> |
1103 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1115 | <pre class=" CodeMirror-line " |
1104 | </span></span></pre> | 1116 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1105 | </div> | 1117 | </div> |
1106 | <div style="position: relative;"> | 1118 | <div style="position: relative;"> |
1107 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1119 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1178,8 +1190,8 @@ | |||
1178 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1190 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1179 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">36</div> | 1191 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">36</div> |
1180 | </div> | 1192 | </div> |
1181 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1193 | <pre class=" CodeMirror-line " |
1182 | </span></span></pre> | 1194 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1183 | </div> | 1195 | </div> |
1184 | <div style="position: relative;"> | 1196 | <div style="position: relative;"> |
1185 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1197 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1207,8 +1219,8 @@ | |||
1207 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | 1219 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" |
1208 | style="left: 0px; width: 26px;">40</div> | 1220 | style="left: 0px; width: 26px;">40</div> |
1209 | </div> | 1221 | </div> |
1210 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1222 | <pre class=" CodeMirror-line " |
1211 | </span></span></pre> | 1223 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1212 | </div> | 1224 | </div> |
1213 | <div style="position: relative;"> | 1225 | <div style="position: relative;"> |
1214 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1226 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1256,8 +1268,8 @@ | |||
1256 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1268 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1257 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">47</div> | 1269 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">47</div> |
1258 | </div> | 1270 | </div> |
1259 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1271 | <pre class=" CodeMirror-line " |
1260 | </span></span></pre> | 1272 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1261 | </div> | 1273 | </div> |
1262 | <div style="position: relative;"> | 1274 | <div style="position: relative;"> |
1263 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1275 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1270,8 +1282,8 @@ | |||
1270 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1282 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1271 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">49</div> | 1283 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">49</div> |
1272 | </div> | 1284 | </div> |
1273 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1285 | <pre class=" CodeMirror-line " |
1274 | </span></span></pre> | 1286 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1275 | </div> | 1287 | </div> |
1276 | <div style="position: relative;"> | 1288 | <div style="position: relative;"> |
1277 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1289 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1320,8 +1332,8 @@ | |||
1320 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1332 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1321 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">56</div> | 1333 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">56</div> |
1322 | </div> | 1334 | </div> |
1323 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1335 | <pre class=" CodeMirror-line " |
1324 | </span></span></pre> | 1336 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1325 | </div> | 1337 | </div> |
1326 | <div style="position: relative;"> | 1338 | <div style="position: relative;"> |
1327 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1339 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1341,8 +1353,8 @@ | |||
1341 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1353 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1342 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">59</div> | 1354 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">59</div> |
1343 | </div> | 1355 | </div> |
1344 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1356 | <pre class=" CodeMirror-line " |
1345 | </span></span></pre> | 1357 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1346 | </div> | 1358 | </div> |
1347 | <div style="position: relative;"> | 1359 | <div style="position: relative;"> |
1348 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1360 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1500,8 +1512,8 @@ | |||
1500 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1512 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1501 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div> | 1513 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">7</div> |
1502 | </div> | 1514 | </div> |
1503 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1515 | <pre class=" CodeMirror-line " |
1504 | </span></span></pre> | 1516 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1505 | </div> | 1517 | </div> |
1506 | <div style="position: relative;"> | 1518 | <div style="position: relative;"> |
1507 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1519 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1607,8 +1619,8 @@ | |||
1607 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1619 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1608 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div> | 1620 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">22</div> |
1609 | </div> | 1621 | </div> |
1610 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1622 | <pre class=" CodeMirror-line " |
1611 | </span></span></pre> | 1623 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1612 | </div> | 1624 | </div> |
1613 | <div style="position: relative;"> | 1625 | <div style="position: relative;"> |
1614 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1626 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1720,8 +1732,8 @@ | |||
1720 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1732 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1721 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">38</div> | 1733 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">38</div> |
1722 | </div> | 1734 | </div> |
1723 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1735 | <pre class=" CodeMirror-line " |
1724 | </span></span></pre> | 1736 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1725 | </div> | 1737 | </div> |
1726 | <div style="position: relative;"> | 1738 | <div style="position: relative;"> |
1727 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1739 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1770,8 +1782,8 @@ | |||
1770 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1782 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1771 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">45</div> | 1783 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">45</div> |
1772 | </div> | 1784 | </div> |
1773 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1785 | <pre class=" CodeMirror-line " |
1774 | </span></span></pre> | 1786 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1775 | </div> | 1787 | </div> |
1776 | <div style="position: relative;"> | 1788 | <div style="position: relative;"> |
1777 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1789 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1813,8 +1825,8 @@ | |||
1813 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1825 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1814 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">51</div> | 1826 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">51</div> |
1815 | </div> | 1827 | </div> |
1816 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1828 | <pre class=" CodeMirror-line " |
1817 | </span></span></pre> | 1829 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1818 | </div> | 1830 | </div> |
1819 | <div style="position: relative;"> | 1831 | <div style="position: relative;"> |
1820 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1832 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1855,8 +1867,8 @@ | |||
1855 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1867 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1856 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">57</div> | 1868 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">57</div> |
1857 | </div> | 1869 | </div> |
1858 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1870 | <pre class=" CodeMirror-line " |
1859 | </span></span></pre> | 1871 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1860 | </div> | 1872 | </div> |
1861 | <div style="position: relative;"> | 1873 | <div style="position: relative;"> |
1862 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1874 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1898,8 +1910,8 @@ | |||
1898 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1910 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1899 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">63</div> | 1911 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">63</div> |
1900 | </div> | 1912 | </div> |
1901 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1913 | <pre class=" CodeMirror-line " |
1902 | </span></span></pre> | 1914 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1903 | </div> | 1915 | </div> |
1904 | <div style="position: relative;"> | 1916 | <div style="position: relative;"> |
1905 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1917 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1919,8 +1931,8 @@ | |||
1919 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1931 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1920 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">66</div> | 1932 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">66</div> |
1921 | </div> | 1933 | </div> |
1922 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 1934 | <pre class=" CodeMirror-line " |
1923 | </span></span></pre> | 1935 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
1924 | </div> | 1936 | </div> |
1925 | <div style="position: relative;"> | 1937 | <div style="position: relative;"> |
1926 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 1938 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -1997,8 +2009,8 @@ | |||
1997 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2009 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
1998 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">77</div> | 2010 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">77</div> |
1999 | </div> | 2011 | </div> |
2000 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2012 | <pre class=" CodeMirror-line " |
2001 | </span></span></pre> | 2013 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2002 | </div> | 2014 | </div> |
2003 | <div style="position: relative;"> | 2015 | <div style="position: relative;"> |
2004 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2016 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2256,8 +2268,8 @@ | |||
2256 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2268 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2257 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div> | 2269 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">21</div> |
2258 | </div> | 2270 | </div> |
2259 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2271 | <pre class=" CodeMirror-line " |
2260 | </span></span></pre> | 2272 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2261 | </div> | 2273 | </div> |
2262 | <div style="position: relative;"> | 2274 | <div style="position: relative;"> |
2263 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2275 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2355,8 +2367,8 @@ | |||
2355 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2367 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2356 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">35</div> | 2368 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">35</div> |
2357 | </div> | 2369 | </div> |
2358 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2370 | <pre class=" CodeMirror-line " |
2359 | </span></span></pre> | 2371 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2360 | </div> | 2372 | </div> |
2361 | <div style="position: relative;"> | 2373 | <div style="position: relative;"> |
2362 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2374 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2454,8 +2466,8 @@ | |||
2454 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2466 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2455 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">49</div> | 2467 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">49</div> |
2456 | </div> | 2468 | </div> |
2457 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2469 | <pre class=" CodeMirror-line " |
2458 | </span></span></pre> | 2470 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2459 | </div> | 2471 | </div> |
2460 | <div style="position: relative;"> | 2472 | <div style="position: relative;"> |
2461 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2473 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2554,8 +2566,8 @@ | |||
2554 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2566 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2555 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">63</div> | 2567 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">63</div> |
2556 | </div> | 2568 | </div> |
2557 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2569 | <pre class=" CodeMirror-line " |
2558 | </span></span></pre> | 2570 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2559 | </div> | 2571 | </div> |
2560 | <div style="position: relative;"> | 2572 | <div style="position: relative;"> |
2561 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2573 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2684,8 +2696,8 @@ | |||
2684 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2696 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2685 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div> | 2697 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">3</div> |
2686 | </div> | 2698 | </div> |
2687 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2699 | <pre class=" CodeMirror-line " |
2688 | </span></span></pre> | 2700 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2689 | </div> | 2701 | </div> |
2690 | <div style="position: relative;"> | 2702 | <div style="position: relative;"> |
2691 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2703 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2719,8 +2731,8 @@ | |||
2719 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2731 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2720 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div> | 2732 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">8</div> |
2721 | </div> | 2733 | </div> |
2722 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2734 | <pre class=" CodeMirror-line " |
2723 | </span></span></pre> | 2735 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2724 | </div> | 2736 | </div> |
2725 | <div style="position: relative;"> | 2737 | <div style="position: relative;"> |
2726 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2738 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2755,8 +2767,8 @@ | |||
2755 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2767 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2756 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div> | 2768 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">13</div> |
2757 | </div> | 2769 | </div> |
2758 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2770 | <pre class=" CodeMirror-line " |
2759 | </span></span></pre> | 2771 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2760 | </div> | 2772 | </div> |
2761 | <div style="position: relative;"> | 2773 | <div style="position: relative;"> |
2762 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2774 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2776,8 +2788,8 @@ | |||
2776 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2788 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2777 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div> | 2789 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">16</div> |
2778 | </div> | 2790 | </div> |
2779 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2791 | <pre class=" CodeMirror-line " |
2780 | </span></span></pre> | 2792 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2781 | </div> | 2793 | </div> |
2782 | <div style="position: relative;"> | 2794 | <div style="position: relative;"> |
2783 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2795 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2805,8 +2817,8 @@ | |||
2805 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | 2817 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" |
2806 | style="left: 0px; width: 26px;">20</div> | 2818 | style="left: 0px; width: 26px;">20</div> |
2807 | </div> | 2819 | </div> |
2808 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2820 | <pre class=" CodeMirror-line " |
2809 | </span></span></pre> | 2821 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2810 | </div> | 2822 | </div> |
2811 | <div style="position: relative;"> | 2823 | <div style="position: relative;"> |
2812 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2824 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2847,8 +2859,8 @@ | |||
2847 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2859 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2848 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">26</div> | 2860 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">26</div> |
2849 | </div> | 2861 | </div> |
2850 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2862 | <pre class=" CodeMirror-line " |
2851 | </span></span></pre> | 2863 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2852 | </div> | 2864 | </div> |
2853 | <div style="position: relative;"> | 2865 | <div style="position: relative;"> |
2854 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2866 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2911,8 +2923,8 @@ | |||
2911 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2923 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2912 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">35</div> | 2924 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">35</div> |
2913 | </div> | 2925 | </div> |
2914 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2926 | <pre class=" CodeMirror-line " |
2915 | </span></span></pre> | 2927 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2916 | </div> | 2928 | </div> |
2917 | <div style="position: relative;"> | 2929 | <div style="position: relative;"> |
2918 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2930 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -2954,8 +2966,8 @@ | |||
2954 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2966 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
2955 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">41</div> | 2967 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">41</div> |
2956 | </div> | 2968 | </div> |
2957 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 2969 | <pre class=" CodeMirror-line " |
2958 | </span></span></pre> | 2970 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
2959 | </div> | 2971 | </div> |
2960 | <div style="position: relative;"> | 2972 | <div style="position: relative;"> |
2961 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 2973 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
@@ -3003,8 +3015,8 @@ | |||
3003 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 3015 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
3004 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">48</div> | 3016 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 26px;">48</div> |
3005 | </div> | 3017 | </div> |
3006 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | 3018 | <pre class=" CodeMirror-line " |
3007 | </span></span></pre> | 3019 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"></span></pre> |
3008 | </div> | 3020 | </div> |
3009 | <div style="position: relative;"> | 3021 | <div style="position: relative;"> |
3010 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> | 3022 | <div class="CodeMirror-gutter-wrapper" style="left: -35px;"> |
diff --git a/code/fileop(cpp).html b/code/fileop(cpp).html deleted file mode 100644 index 9c771fe..0000000 --- a/code/fileop(cpp).html +++ /dev/null | |||
@@ -1,1007 +0,0 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | |||
4 | <head> | ||
5 | <meta charset='UTF-8'> | ||
6 | <meta name='viewport' content='width=device-width initial-scale=1'> | ||
7 | <link href='https://fonts.loli.net/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext' | ||
8 | rel='stylesheet' type='text/css' /> | ||
9 | <title>fileop(cpp)</title> | ||
10 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/github.css"> | ||
11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | ||
12 | </head> | ||
13 | |||
14 | <body class='typora-export os-windows'> | ||
15 | <div class='typora-export-content'> | ||
16 | <div id='write' class=''> | ||
17 | <div class='md-toc' mdtype='toc'> | ||
18 | <p class="md-toc-content" role="list"><span role="listitem" class="md-toc-item md-toc-h1" | ||
19 | data-ref="n62"><a class="md-toc-inner" href="#头文件">头文件</a></span><span role="listitem" | ||
20 | class="md-toc-item md-toc-h1" data-ref="n64"><a class="md-toc-inner" | ||
21 | href="#对象声明">对象声明</a></span><span role="listitem" class="md-toc-item md-toc-h1" | ||
22 | data-ref="n66"><a class="md-toc-inner" href="#文件打开关闭">文件打开、关闭</a></span><span role="listitem" | ||
23 | class="md-toc-item md-toc-h1" data-ref="n98"><a class="md-toc-inner" | ||
24 | href="#文件操作">文件操作</a></span><span role="listitem" class="md-toc-item md-toc-h1" | ||
25 | data-ref="n102"><a class="md-toc-inner" href="#文本文件">文本文件</a></span><span role="listitem" | ||
26 | class="md-toc-item md-toc-h2" data-ref="n103"><a class="md-toc-inner" | ||
27 | href="#读取-1">读取</a></span><span role="listitem" class="md-toc-item md-toc-h2" | ||
28 | data-ref="n106"><a class="md-toc-inner" href="#文件写入">文件写入</a></span><span role="listitem" | ||
29 | class="md-toc-item md-toc-h2" data-ref="n109"><a class="md-toc-inner" | ||
30 | href="#总结">总结</a></span><span role="listitem" class="md-toc-item md-toc-h1" | ||
31 | data-ref="n111"><a class="md-toc-inner" href="#二进制文件">二进制文件</a></span><span role="listitem" | ||
32 | class="md-toc-item md-toc-h2" data-ref="n113"><a class="md-toc-inner" | ||
33 | href="#读取-2">读取</a></span><span role="listitem" class="md-toc-item md-toc-h2" | ||
34 | data-ref="n116"><a class="md-toc-inner" href="#写入">写入</a></span></p> | ||
35 | </div> | ||
36 | <h1 id='头文件'><span>头文件</span></h1> | ||
37 | <p><span>C++文件操作头文件 fstream,也就是“文件流”。</span></p> | ||
38 | <h1 id='对象声明'><span>对象声明</span></h1> | ||
39 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" | ||
40 | lang="C++"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c++"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
41 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
42 | <div>3</div> | ||
43 | </div> | ||
44 | </div> | ||
45 | <div class="CodeMirror-measure"></div> | ||
46 | <div style="position: relative; z-index: 1;"></div> | ||
47 | <div class="CodeMirror-code" role="presentation"> | ||
48 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
49 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
50 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" | ||
51 | style="left: -28px; width: 28px;"></div> | ||
52 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"> | ||
53 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
54 | style="left: 0px; width: 19px;">1</div> | ||
55 | </div> | ||
56 | <pre class=" CodeMirror-line " | ||
57 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">ofstream</span> <span class="cm-variable">ofs</span>;<span class="cm-comment">//执行写操作</span></span></pre> | ||
58 | </div> | ||
59 | <div style="position: relative;"> | ||
60 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
61 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div> | ||
62 | </div> | ||
63 | <pre class=" CodeMirror-line " | ||
64 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">ifstream</span> <span class="cm-variable">ifs</span>;<span class="cm-comment">//执行读操作</span></span></pre> | ||
65 | </div> | ||
66 | <div style="position: relative;"> | ||
67 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
68 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
69 | style="left: 0px; width: 19px;">3</div> | ||
70 | </div> | ||
71 | <pre class=" CodeMirror-line " | ||
72 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">fstream</span> <span class="cm-variable">file</span>;<span class="cm-comment">//读写都可以</span></span></pre> | ||
73 | </div> | ||
74 | </div> | ||
75 | </div> | ||
76 | </div> | ||
77 | </div> | ||
78 | </div> | ||
79 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 69px;"></div> | ||
80 | <div class="CodeMirror-gutters" style="height: 69px;"> | ||
81 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div> | ||
82 | </div> | ||
83 | </div> | ||
84 | </div> | ||
85 | </pre> | ||
86 | <h1 id='文件打开关闭'><span>文件打开、关闭</span></h1> | ||
87 | <p><span>以下所有内容均假设使用对象名为 file(不论是 ofstream 还是 ifstream/fstream),打开方式为:</span><code>file.open(文件路径,打开方式);</code> | ||
88 | <span>同时也可以在定义流对象时直接打开:</span> | ||
89 | <code>ifstream file(文件路径,打开方式)</code> | ||
90 | <span>其中,文件路径的参数为 string 类型字符串或 char</span><span>*</span><span>型字符数组。</span> | ||
91 | </p> | ||
92 | <figure> | ||
93 | <table> | ||
94 | <thead> | ||
95 | <tr> | ||
96 | <th style='text-align:center;'><span>打开方式</span></th> | ||
97 | <th style='text-align:center;'><span>解释</span></th> | ||
98 | </tr> | ||
99 | </thead> | ||
100 | <tbody> | ||
101 | <tr> | ||
102 | <td style='text-align:center;'><span>ios::in</span></td> | ||
103 | <td style='text-align:center;'><span>读取</span></td> | ||
104 | </tr> | ||
105 | <tr> | ||
106 | <td style='text-align:center;'><span>ios::out</span></td> | ||
107 | <td style='text-align:center;'><span>写入</span></td> | ||
108 | </tr> | ||
109 | <tr> | ||
110 | <td style='text-align:center;'><span>ios::ate</span></td> | ||
111 | <td style='text-align:center;'><span>初始位置:文件尾</span></td> | ||
112 | </tr> | ||
113 | <tr> | ||
114 | <td style='text-align:center;'><span>ios::app</span></td> | ||
115 | <td style='text-align:center;'><span>追加方式写文件</span></td> | ||
116 | </tr> | ||
117 | <tr> | ||
118 | <td style='text-align:center;'><span>ios::trunc</span></td> | ||
119 | <td style='text-align:center;'><span>如果文件存在先删除,再创建</span></td> | ||
120 | </tr> | ||
121 | <tr> | ||
122 | <td style='text-align:center;'><span>ios::binary</span></td> | ||
123 | <td style='text-align:center;'><span>二进制方式</span></td> | ||
124 | </tr> | ||
125 | </tbody> | ||
126 | </table> | ||
127 | </figure> | ||
128 | <p><span>文件关闭:</span><code>file.close();</code> | ||
129 | <span>文件关闭之后流并未删除,只是断开了流到文件的链接,流管理装置仍然保留,因而可以用来再次打开某个文件。此时由于之前使用的内容还储存着,为避免对之后的使用造成影响,应当在文件关闭后使用函数</span><code>file.clear()</code><span>把整个类全部重置。</span> | ||
130 | </p> | ||
131 | <ul> | ||
132 | <li>注意:文件打开方式可以配合使用,利用 | 操作符。例如,用二进制方式写文件:<br><code>ios::out | ios::binary</code></li> | ||
133 | <li>ios 即 basic_ios,二者互为别名;ios 类是在 ios_base 基础上的派生类。</li> | ||
134 | <li>打开方式可以不写,默认打开方式为<code>ios::in|ios::out</code>,以默认模式打开文件进行输出(写入)时,文件长度将自动截短为0,也就是删除之前内容。</li> | ||
135 | </ul> | ||
136 | <h1 id='文件操作'><span>文件操作</span></h1> | ||
137 | <ul> | ||
138 | <li>由于<code>ifstream</code>、<code>ofstream</code>、<code>fstream</code>等<code>fstream</code>中定义的类都是从<code>iostream</code>的相应类中派生而来,所以均可使用原来的类的操作方法,并且继承其特性(如ifs 会和 cin 一样,遇到空格就截断字符串)。一如 C 语言中的 gets/fgets、scanf/fscanf、printf/fprintf。</li> | ||
139 | </ul> | ||
140 | <h1 id='文本文件'><span>文本文件</span></h1> | ||
141 | <h2 id='读取-1'><span>读取</span></h2> | ||
142 | <p><span>五种方法。例程如下:</span></p> | ||
143 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="C++" | ||
144 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c++"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
145 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
146 | <div>44</div> | ||
147 | </div> | ||
148 | </div> | ||
149 | <div class="CodeMirror-measure"></div> | ||
150 | <div style="position: relative; z-index: 1;"></div> | ||
151 | <div class="CodeMirror-code" role="presentation" style=""> | ||
152 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
153 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
154 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
155 | </div> | ||
156 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
157 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
158 | style="left: 0px; width: 27px;">1</div> | ||
159 | </div> | ||
160 | <pre class=" CodeMirror-line " | ||
161 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre> | ||
162 | </div> | ||
163 | <div style="position: relative;"> | ||
164 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
165 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
166 | </div> | ||
167 | <pre class=" CodeMirror-line " | ||
168 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre> | ||
169 | </div> | ||
170 | <div style="position: relative;"> | ||
171 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
172 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
173 | </div> | ||
174 | <pre class=" CodeMirror-line " | ||
175 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <fstream></span></span></pre> | ||
176 | </div> | ||
177 | <div style="position: relative;"> | ||
178 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
179 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
180 | </div> | ||
181 | <pre class=" CodeMirror-line " | ||
182 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre> | ||
183 | </div> | ||
184 | <div style="position: relative;"> | ||
185 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
186 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
187 | </div> | ||
188 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
189 | </span></span></pre> | ||
190 | </div> | ||
191 | <div style="position: relative;"> | ||
192 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
193 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
194 | </div> | ||
195 | <pre class=" CodeMirror-line " | ||
196 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre> | ||
197 | </div> | ||
198 | <div style="position: relative;"> | ||
199 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
200 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
201 | </div> | ||
202 | <pre class=" CodeMirror-line " | ||
203 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
204 | </div> | ||
205 | <div style="position: relative;"> | ||
206 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
207 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
208 | </div> | ||
209 | <pre class=" CodeMirror-line " | ||
210 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifstream</span> <span class="cm-variable">ifs</span>;</span></pre> | ||
211 | </div> | ||
212 | <div style="position: relative;"> | ||
213 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
214 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
215 | </div> | ||
216 | <pre class=" CodeMirror-line " | ||
217 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">char</span> <span class="cm-variable">buf</span>[<span class="cm-number">1000</span>] <span class="cm-operator">=</span> { <span class="cm-number">0</span> };</span></pre> | ||
218 | </div> | ||
219 | <div style="position: relative;"> | ||
220 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
221 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
222 | style="left: 0px; width: 27px;">10</div> | ||
223 | </div> | ||
224 | <pre class=" CodeMirror-line " | ||
225 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">string</span> <span class="cm-variable">s</span>;</span></pre> | ||
226 | </div> | ||
227 | <div style="position: relative;"> | ||
228 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
229 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
230 | </div> | ||
231 | <pre class=" CodeMirror-line " | ||
232 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifs</span>.<span class="cm-variable">open</span>(<span class="cm-string">"test.txt"</span>,<span class="cm-variable">ios::in</span>);</span></pre> | ||
233 | </div> | ||
234 | <div style="position: relative;"> | ||
235 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
236 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
237 | </div> | ||
238 | <pre class=" CodeMirror-line " | ||
239 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">if</span>(<span class="cm-operator">!</span><span class="cm-variable">ifs</span>.<span class="cm-variable">is_open</span>())</span></pre> | ||
240 | </div> | ||
241 | <div style="position: relative;"> | ||
242 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
243 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
244 | </div> | ||
245 | <pre class=" CodeMirror-line " | ||
246 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
247 | </div> | ||
248 | <div style="position: relative;"> | ||
249 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
250 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
251 | </div> | ||
252 | <pre class=" CodeMirror-line " | ||
253 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"文件打开失败!"</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre> | ||
254 | </div> | ||
255 | <div style="position: relative;"> | ||
256 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
257 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
258 | </div> | ||
259 | <pre class=" CodeMirror-line " | ||
260 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-operator">-</span><span class="cm-number">1</span>;</span></pre> | ||
261 | </div> | ||
262 | <div style="position: relative;"> | ||
263 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
264 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
265 | </div> | ||
266 | <pre class=" CodeMirror-line " | ||
267 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
268 | </div> | ||
269 | <div style="position: relative;"> | ||
270 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
271 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
272 | </div> | ||
273 | <pre class=" CodeMirror-line " | ||
274 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">/*方法一,缺点在于空格即断开*/</span></span></pre> | ||
275 | </div> | ||
276 | <div style="position: relative;"> | ||
277 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
278 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | ||
279 | </div> | ||
280 | <pre class=" CodeMirror-line " | ||
281 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">while</span>(<span class="cm-variable">ifs</span> <span class="cm-operator">>></span> <span class="cm-variable">buf</span>)</span></pre> | ||
282 | </div> | ||
283 | <div style="position: relative;"> | ||
284 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
285 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
286 | </div> | ||
287 | <pre class=" CodeMirror-line " | ||
288 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
289 | </div> | ||
290 | <div style="position: relative;"> | ||
291 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
292 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
293 | style="left: 0px; width: 27px;">20</div> | ||
294 | </div> | ||
295 | <pre class=" CodeMirror-line " | ||
296 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">buf</span> <span class="cm-operator"><<</span><span class="cm-variable">endl</span>;</span></pre> | ||
297 | </div> | ||
298 | <div style="position: relative;"> | ||
299 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
300 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div> | ||
301 | </div> | ||
302 | <pre class=" CodeMirror-line " | ||
303 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
304 | </div> | ||
305 | <div style="position: relative;"> | ||
306 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
307 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div> | ||
308 | </div> | ||
309 | <pre class=" CodeMirror-line " | ||
310 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">/*方法二,缺点同上*/</span></span></pre> | ||
311 | </div> | ||
312 | <div style="position: relative;"> | ||
313 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
314 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div> | ||
315 | </div> | ||
316 | <pre class=" CodeMirror-line " | ||
317 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">while</span>(<span class="cm-variable">ifs</span>.<span class="cm-variable">getline</span>(<span class="cm-variable">buf</span>,<span class="cm-keyword">sizeof</span>(<span class="cm-variable">buf</span>)))</span></pre> | ||
318 | </div> | ||
319 | <div style="position: relative;"> | ||
320 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
321 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div> | ||
322 | </div> | ||
323 | <pre class=" CodeMirror-line " | ||
324 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
325 | </div> | ||
326 | <div style="position: relative;"> | ||
327 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
328 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div> | ||
329 | </div> | ||
330 | <pre class=" CodeMirror-line " | ||
331 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">buf</span> <span class="cm-operator"><<</span><span class="cm-variable">endl</span>;</span></pre> | ||
332 | </div> | ||
333 | <div style="position: relative;"> | ||
334 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
335 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div> | ||
336 | </div> | ||
337 | <pre class=" CodeMirror-line " | ||
338 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
339 | </div> | ||
340 | <div style="position: relative;"> | ||
341 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
342 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div> | ||
343 | </div> | ||
344 | <pre class=" CodeMirror-line " | ||
345 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">/*方法三,整行读取*/</span></span></pre> | ||
346 | </div> | ||
347 | <div style="position: relative;"> | ||
348 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
349 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div> | ||
350 | </div> | ||
351 | <pre class=" CodeMirror-line " | ||
352 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">while</span>(<span class="cm-variable">getline</span>(<span class="cm-variable">ifs</span>,<span class="cm-variable">s</span>))</span></pre> | ||
353 | </div> | ||
354 | <div style="position: relative;"> | ||
355 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
356 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div> | ||
357 | </div> | ||
358 | <pre class=" CodeMirror-line " | ||
359 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
360 | </div> | ||
361 | <div style="position: relative;"> | ||
362 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
363 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
364 | style="left: 0px; width: 27px;">30</div> | ||
365 | </div> | ||
366 | <pre class=" CodeMirror-line " | ||
367 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-variable">buf</span> <span class="cm-operator"><<</span><span class="cm-variable">endl</span>;</span></pre> | ||
368 | </div> | ||
369 | <div style="position: relative;"> | ||
370 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
371 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div> | ||
372 | </div> | ||
373 | <pre class=" CodeMirror-line " | ||
374 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
375 | </div> | ||
376 | <div style="position: relative;"> | ||
377 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
378 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div> | ||
379 | </div> | ||
380 | <pre class=" CodeMirror-line " | ||
381 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">/*方法四,逐个字符读取,太不爽*/</span></span></pre> | ||
382 | </div> | ||
383 | <div style="position: relative;"> | ||
384 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
385 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div> | ||
386 | </div> | ||
387 | <pre class=" CodeMirror-line " | ||
388 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">char</span> <span class="cm-variable">c</span>;</span></pre> | ||
389 | </div> | ||
390 | <div style="position: relative;"> | ||
391 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
392 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div> | ||
393 | </div> | ||
394 | <pre class=" CodeMirror-line " | ||
395 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">while</span>((<span class="cm-variable">c</span> <span class="cm-operator">=</span> <span class="cm-variable">ifs</span>.<span class="cm-variable">get</span>()) <span class="cm-operator">!=</span> <span class="cm-variable">EOF</span>)</span></pre> | ||
396 | </div> | ||
397 | <div style="position: relative;"> | ||
398 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
399 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div> | ||
400 | </div> | ||
401 | <pre class=" CodeMirror-line " | ||
402 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
403 | </div> | ||
404 | <div style="position: relative;"> | ||
405 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
406 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div> | ||
407 | </div> | ||
408 | <pre class=" CodeMirror-line " | ||
409 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-variable">c</span>;</span></pre> | ||
410 | </div> | ||
411 | <div style="position: relative;"> | ||
412 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
413 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div> | ||
414 | </div> | ||
415 | <pre class=" CodeMirror-line " | ||
416 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
417 | </div> | ||
418 | <div style="position: relative;"> | ||
419 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
420 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div> | ||
421 | </div> | ||
422 | <pre class=" CodeMirror-line " | ||
423 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">/*方法五,缺点在和cin一样,遇到空格就截断,而不只是换行符*/</span></span></pre> | ||
424 | </div> | ||
425 | <div style="position: relative;"> | ||
426 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
427 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div> | ||
428 | </div> | ||
429 | <pre class=" CodeMirror-line " | ||
430 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifs</span> <span class="cm-operator">>></span> <span class="cm-variable">buf</span>;</span></pre> | ||
431 | </div> | ||
432 | <div style="position: relative;"> | ||
433 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
434 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
435 | style="left: 0px; width: 27px;">40</div> | ||
436 | </div> | ||
437 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
438 | </span></span></pre> | ||
439 | </div> | ||
440 | <div style="position: relative;"> | ||
441 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
442 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div> | ||
443 | </div> | ||
444 | <pre class=" CodeMirror-line " | ||
445 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifs</span>.<span class="cm-variable">close</span>();</span></pre> | ||
446 | </div> | ||
447 | <div style="position: relative;"> | ||
448 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
449 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div> | ||
450 | </div> | ||
451 | <pre class=" CodeMirror-line " | ||
452 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifs</span>.<span class="cm-variable">clear</span>();</span></pre> | ||
453 | </div> | ||
454 | <div style="position: relative;"> | ||
455 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
456 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div> | ||
457 | </div> | ||
458 | <pre class=" CodeMirror-line " | ||
459 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre> | ||
460 | </div> | ||
461 | <div style="position: relative;"> | ||
462 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
463 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
464 | style="left: 0px; width: 27px;">44</div> | ||
465 | </div> | ||
466 | <pre class=" CodeMirror-line " | ||
467 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
468 | </div> | ||
469 | </div> | ||
470 | </div> | ||
471 | </div> | ||
472 | </div> | ||
473 | </div> | ||
474 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1014px;"></div> | ||
475 | <div class="CodeMirror-gutters" style="height: 1014px;"> | ||
476 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
477 | </div> | ||
478 | </div> | ||
479 | </div> | ||
480 | </pre> | ||
481 | <h2 id='文件写入'><span>文件写入</span></h2> | ||
482 | <p><span>格式如下:</span> | ||
483 | <code>对象名 << 写入的内容;</code> | ||
484 | <span>如需换行,在写入内容后加 endl 即可。例程如下:</span> | ||
485 | </p> | ||
486 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="C++" | ||
487 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c++"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
488 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
489 | <div>21</div> | ||
490 | </div> | ||
491 | </div> | ||
492 | <div class="CodeMirror-measure"></div> | ||
493 | <div style="position: relative; z-index: 1;"></div> | ||
494 | <div class="CodeMirror-code" role="presentation" style=""> | ||
495 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
496 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
497 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
498 | </div> | ||
499 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
500 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
501 | style="left: 0px; width: 27px;">1</div> | ||
502 | </div> | ||
503 | <pre class=" CodeMirror-line " | ||
504 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre> | ||
505 | </div> | ||
506 | <div style="position: relative;"> | ||
507 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
508 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
509 | </div> | ||
510 | <pre class=" CodeMirror-line " | ||
511 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre> | ||
512 | </div> | ||
513 | <div style="position: relative;"> | ||
514 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
515 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
516 | </div> | ||
517 | <pre class=" CodeMirror-line " | ||
518 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <fstream></span></span></pre> | ||
519 | </div> | ||
520 | <div style="position: relative;"> | ||
521 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
522 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
523 | </div> | ||
524 | <pre class=" CodeMirror-line " | ||
525 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre> | ||
526 | </div> | ||
527 | <div style="position: relative;"> | ||
528 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
529 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
530 | </div> | ||
531 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
532 | </span></span></pre> | ||
533 | </div> | ||
534 | <div style="position: relative;"> | ||
535 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
536 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
537 | </div> | ||
538 | <pre class=" CodeMirror-line " | ||
539 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre> | ||
540 | </div> | ||
541 | <div style="position: relative;"> | ||
542 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
543 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
544 | </div> | ||
545 | <pre class=" CodeMirror-line " | ||
546 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
547 | </div> | ||
548 | <div style="position: relative;"> | ||
549 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
550 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
551 | </div> | ||
552 | <pre class=" CodeMirror-line " | ||
553 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofstream</span> <span class="cm-variable">ofs</span>;</span></pre> | ||
554 | </div> | ||
555 | <div style="position: relative;"> | ||
556 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
557 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
558 | </div> | ||
559 | <pre class=" CodeMirror-line " | ||
560 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span>.<span class="cm-variable">open</span>(<span class="cm-string">"test.txt"</span>,<span class="cm-variable">ios::out</span>);</span></pre> | ||
561 | </div> | ||
562 | <div style="position: relative;"> | ||
563 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
564 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
565 | style="left: 0px; width: 27px;">10</div> | ||
566 | </div> | ||
567 | <pre class=" CodeMirror-line " | ||
568 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">if</span>(<span class="cm-operator">!</span><span class="cm-variable">ofs</span>.<span class="cm-variable">is_open</span>())</span></pre> | ||
569 | </div> | ||
570 | <div style="position: relative;"> | ||
571 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
572 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
573 | </div> | ||
574 | <pre class=" CodeMirror-line " | ||
575 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
576 | </div> | ||
577 | <div style="position: relative;"> | ||
578 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
579 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
580 | </div> | ||
581 | <pre class=" CodeMirror-line " | ||
582 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"文件打开失败!"</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre> | ||
583 | </div> | ||
584 | <div style="position: relative;"> | ||
585 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
586 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
587 | </div> | ||
588 | <pre class=" CodeMirror-line " | ||
589 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-operator">-</span><span class="cm-number">1</span>;</span></pre> | ||
590 | </div> | ||
591 | <div style="position: relative;"> | ||
592 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
593 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
594 | </div> | ||
595 | <pre class=" CodeMirror-line " | ||
596 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
597 | </div> | ||
598 | <div style="position: relative;"> | ||
599 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
600 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
601 | </div> | ||
602 | <pre class=" CodeMirror-line " | ||
603 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span> <span class="cm-operator"><<</span> <span class="cm-string">"-How old are you?"</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre> | ||
604 | </div> | ||
605 | <div style="position: relative;"> | ||
606 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
607 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
608 | </div> | ||
609 | <pre class=" CodeMirror-line " | ||
610 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span> <span class="cm-operator"><<</span> <span class="cm-string">"-I'm 21ys old."</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre> | ||
611 | </div> | ||
612 | <div style="position: relative;"> | ||
613 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
614 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
615 | </div> | ||
616 | <pre class=" CodeMirror-line " | ||
617 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span> <span class="cm-operator"><<</span> <span class="cm-string">"-Oh,what a young guy!"</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre> | ||
618 | </div> | ||
619 | <div style="position: relative;"> | ||
620 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
621 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | ||
622 | </div> | ||
623 | <pre class=" CodeMirror-line " | ||
624 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span> <span class="cm-operator"><<</span> <span class="cm-string">"-Thanks."</span> <span class="cm-operator"><<</span><span class="cm-variable">endl</span>;</span></pre> | ||
625 | </div> | ||
626 | <div style="position: relative;"> | ||
627 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
628 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
629 | </div> | ||
630 | <pre class=" CodeMirror-line " | ||
631 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span>.<span class="cm-variable">close</span>();</span></pre> | ||
632 | </div> | ||
633 | <div style="position: relative;"> | ||
634 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
635 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
636 | style="left: 0px; width: 27px;">20</div> | ||
637 | </div> | ||
638 | <pre class=" CodeMirror-line " | ||
639 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre> | ||
640 | </div> | ||
641 | <div style="position: relative;"> | ||
642 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
643 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
644 | style="left: 0px; width: 27px;">21</div> | ||
645 | </div> | ||
646 | <pre class=" CodeMirror-line " | ||
647 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
648 | </div> | ||
649 | </div> | ||
650 | </div> | ||
651 | </div> | ||
652 | </div> | ||
653 | </div> | ||
654 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 484px;"></div> | ||
655 | <div class="CodeMirror-gutters" style="height: 484px;"> | ||
656 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
657 | </div> | ||
658 | </div> | ||
659 | </div> | ||
660 | </pre> | ||
661 | <h2 id='总结'><span>总结</span></h2> | ||
662 | <p><span>读文件可以利用 ifstream 或者 fstream 类。</span> | ||
663 | <span>利用 is_open 函数可以判断文件是否打开成功。</span> | ||
664 | <span>操作完毕,要关闭文件。</span> | ||
665 | </p> | ||
666 | <h1 id='二进制文件'><span>二进制文件</span></h1> | ||
667 | <p><span>以二进制形式读写文件。</span> | ||
668 | <span>打开方式需要指定为</span><code>ios::binary</code><span>。</span> | ||
669 | </p> | ||
670 | <h2 id='读取-2'><span>读取</span></h2> | ||
671 | <p><span>利用流对象调用成员函数</span><code>read</code><span>。</span> | ||
672 | <span>函数原型:</span><code>istream& read(char* buffer, int len)</code> | ||
673 | <span>参数解释:字符指针 buffer 指向内存中一段存储空间。len 是读写的字节数。</span> | ||
674 | <span>例程如下:</span> | ||
675 | </p> | ||
676 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c++" | ||
677 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c++"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
678 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
679 | <div>18</div> | ||
680 | </div> | ||
681 | </div> | ||
682 | <div class="CodeMirror-measure"></div> | ||
683 | <div style="position: relative; z-index: 1;"></div> | ||
684 | <div class="CodeMirror-code" role="presentation" style=""> | ||
685 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
686 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
687 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
688 | </div> | ||
689 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
690 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
691 | style="left: 0px; width: 27px;">1</div> | ||
692 | </div> | ||
693 | <pre class=" CodeMirror-line " | ||
694 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre> | ||
695 | </div> | ||
696 | <div style="position: relative;"> | ||
697 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
698 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
699 | </div> | ||
700 | <pre class=" CodeMirror-line " | ||
701 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre> | ||
702 | </div> | ||
703 | <div style="position: relative;"> | ||
704 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
705 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
706 | </div> | ||
707 | <pre class=" CodeMirror-line " | ||
708 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <fstream></span></span></pre> | ||
709 | </div> | ||
710 | <div style="position: relative;"> | ||
711 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
712 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
713 | </div> | ||
714 | <pre class=" CodeMirror-line " | ||
715 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre> | ||
716 | </div> | ||
717 | <div style="position: relative;"> | ||
718 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
719 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
720 | </div> | ||
721 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
722 | </span></span></pre> | ||
723 | </div> | ||
724 | <div style="position: relative;"> | ||
725 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
726 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
727 | </div> | ||
728 | <pre class=" CodeMirror-line " | ||
729 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre> | ||
730 | </div> | ||
731 | <div style="position: relative;"> | ||
732 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
733 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
734 | </div> | ||
735 | <pre class=" CodeMirror-line " | ||
736 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
737 | </div> | ||
738 | <div style="position: relative;"> | ||
739 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
740 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
741 | </div> | ||
742 | <pre class=" CodeMirror-line " | ||
743 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifstream</span> <span class="cm-variable">ifs</span>;</span></pre> | ||
744 | </div> | ||
745 | <div style="position: relative;"> | ||
746 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
747 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
748 | </div> | ||
749 | <pre class=" CodeMirror-line " | ||
750 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">int</span> <span class="cm-variable">a</span>[<span class="cm-number">10</span>];</span></pre> | ||
751 | </div> | ||
752 | <div style="position: relative;"> | ||
753 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
754 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
755 | style="left: 0px; width: 27px;">10</div> | ||
756 | </div> | ||
757 | <pre class=" CodeMirror-line " | ||
758 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifs</span>.<span class="cm-variable">open</span>(<span class="cm-string">"test.bin"</span>,<span class="cm-variable">ios::in</span> <span class="cm-operator">|</span> <span class="cm-variable">ios::binary</span>);</span></pre> | ||
759 | </div> | ||
760 | <div style="position: relative;"> | ||
761 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
762 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
763 | </div> | ||
764 | <pre class=" CodeMirror-line " | ||
765 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">if</span>(<span class="cm-operator">!</span><span class="cm-variable">ifs</span>.<span class="cm-variable">is_open</span>())</span></pre> | ||
766 | </div> | ||
767 | <div style="position: relative;"> | ||
768 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
769 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
770 | </div> | ||
771 | <pre class=" CodeMirror-line " | ||
772 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
773 | </div> | ||
774 | <div style="position: relative;"> | ||
775 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
776 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
777 | </div> | ||
778 | <pre class=" CodeMirror-line " | ||
779 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"文件打开失败!"</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre> | ||
780 | </div> | ||
781 | <div style="position: relative;"> | ||
782 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
783 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
784 | </div> | ||
785 | <pre class=" CodeMirror-line " | ||
786 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-operator">-</span><span class="cm-number">1</span>;</span></pre> | ||
787 | </div> | ||
788 | <div style="position: relative;"> | ||
789 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
790 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
791 | </div> | ||
792 | <pre class=" CodeMirror-line " | ||
793 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
794 | </div> | ||
795 | <div style="position: relative;"> | ||
796 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
797 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
798 | </div> | ||
799 | <pre class=" CodeMirror-line " | ||
800 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifs</span>.<span class="cm-variable">read</span>((<span class="cm-variable-3">char*</span>)<span class="cm-variable">a</span>, <span class="cm-keyword">sizeof</span>(<span class="cm-variable-3">int</span>) <span class="cm-operator">*</span> <span class="cm-number">10</span>);</span></pre> | ||
801 | </div> | ||
802 | <div style="position: relative;"> | ||
803 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
804 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
805 | </div> | ||
806 | <pre class=" CodeMirror-line " | ||
807 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre> | ||
808 | </div> | ||
809 | <div style="position: relative;"> | ||
810 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
811 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
812 | style="left: 0px; width: 27px;">18</div> | ||
813 | </div> | ||
814 | <pre class=" CodeMirror-line " | ||
815 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
816 | </div> | ||
817 | </div> | ||
818 | </div> | ||
819 | </div> | ||
820 | </div> | ||
821 | </div> | ||
822 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 415px;"></div> | ||
823 | <div class="CodeMirror-gutters" style="height: 415px;"> | ||
824 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
825 | </div> | ||
826 | </div> | ||
827 | </div> | ||
828 | </pre> | ||
829 | <h2 id='写入'><span>写入</span></h2> | ||
830 | <p><span>使用流对象成员函数</span><code>write</code><span>。</span> | ||
831 | <span>函数原型:</span><code>ostream& write(const char* buffer, int len)</code> | ||
832 | <span>参数解释:字符指针 buffer 指向内存中一段存储空间。len 是读写的字节数。</span> | ||
833 | <span>例程如下:</span> | ||
834 | </p> | ||
835 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c++" | ||
836 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c++"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
837 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
838 | <div>20</div> | ||
839 | </div> | ||
840 | </div> | ||
841 | <div class="CodeMirror-measure"></div> | ||
842 | <div style="position: relative; z-index: 1;"></div> | ||
843 | <div class="CodeMirror-code" role="presentation" style=""> | ||
844 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
845 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
846 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
847 | </div> | ||
848 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
849 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
850 | style="left: 0px; width: 27px;">1</div> | ||
851 | </div> | ||
852 | <pre class=" CodeMirror-line " | ||
853 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <iostream></span></span></pre> | ||
854 | </div> | ||
855 | <div style="position: relative;"> | ||
856 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
857 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
858 | </div> | ||
859 | <pre class=" CodeMirror-line " | ||
860 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <string></span></span></pre> | ||
861 | </div> | ||
862 | <div style="position: relative;"> | ||
863 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
864 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
865 | </div> | ||
866 | <pre class=" CodeMirror-line " | ||
867 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <fstream></span></span></pre> | ||
868 | </div> | ||
869 | <div style="position: relative;"> | ||
870 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
871 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
872 | </div> | ||
873 | <pre class=" CodeMirror-line " | ||
874 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre> | ||
875 | </div> | ||
876 | <div style="position: relative;"> | ||
877 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
878 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
879 | </div> | ||
880 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
881 | </span></span></pre> | ||
882 | </div> | ||
883 | <div style="position: relative;"> | ||
884 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
885 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
886 | </div> | ||
887 | <pre class=" CodeMirror-line " | ||
888 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre> | ||
889 | </div> | ||
890 | <div style="position: relative;"> | ||
891 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
892 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
893 | </div> | ||
894 | <pre class=" CodeMirror-line " | ||
895 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
896 | </div> | ||
897 | <div style="position: relative;"> | ||
898 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
899 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
900 | </div> | ||
901 | <pre class=" CodeMirror-line " | ||
902 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofstream</span> <span class="cm-variable">ofs</span>;</span></pre> | ||
903 | </div> | ||
904 | <div style="position: relative;"> | ||
905 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
906 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
907 | </div> | ||
908 | <pre class=" CodeMirror-line " | ||
909 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">int</span> <span class="cm-variable">c</span><span class="cm-operator">=-</span><span class="cm-number">3</span>;</span></pre> | ||
910 | </div> | ||
911 | <div style="position: relative;"> | ||
912 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
913 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
914 | style="left: 0px; width: 27px;">10</div> | ||
915 | </div> | ||
916 | <pre class=" CodeMirror-line " | ||
917 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">string</span> <span class="cm-variable">s</span><span class="cm-operator">=</span><span class="cm-string">"Long Live the People!"</span>;</span></pre> | ||
918 | </div> | ||
919 | <div style="position: relative;"> | ||
920 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
921 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
922 | </div> | ||
923 | <pre class=" CodeMirror-line " | ||
924 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ifs</span>.<span class="cm-variable">open</span>(<span class="cm-string">"test.bin"</span>,<span class="cm-variable">ios::in</span> <span class="cm-operator">|</span> <span class="cm-variable">ios::binary</span>);</span></pre> | ||
925 | </div> | ||
926 | <div style="position: relative;"> | ||
927 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
928 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
929 | </div> | ||
930 | <pre class=" CodeMirror-line " | ||
931 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">if</span>(<span class="cm-operator">!</span><span class="cm-variable">ofs</span>.<span class="cm-variable">is_open</span>())</span></pre> | ||
932 | </div> | ||
933 | <div style="position: relative;"> | ||
934 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
935 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
936 | </div> | ||
937 | <pre class=" CodeMirror-line " | ||
938 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
939 | </div> | ||
940 | <div style="position: relative;"> | ||
941 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
942 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
943 | </div> | ||
944 | <pre class=" CodeMirror-line " | ||
945 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span> <span class="cm-operator"><<</span> <span class="cm-string">"文件打开失败!"</span> <span class="cm-operator"><<</span> <span class="cm-variable">endl</span>;</span></pre> | ||
946 | </div> | ||
947 | <div style="position: relative;"> | ||
948 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
949 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
950 | </div> | ||
951 | <pre class=" CodeMirror-line " | ||
952 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-operator">-</span><span class="cm-number">1</span>;</span></pre> | ||
953 | </div> | ||
954 | <div style="position: relative;"> | ||
955 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
956 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
957 | </div> | ||
958 | <pre class=" CodeMirror-line " | ||
959 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
960 | </div> | ||
961 | <div style="position: relative;"> | ||
962 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
963 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
964 | </div> | ||
965 | <pre class=" CodeMirror-line " | ||
966 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span>.<span class="cm-variable">read</span>((<span class="cm-variable-3">char*</span>)<span class="cm-operator">&</span><span class="cm-variable">c</span>,<span class="cm-keyword">sizeof</span>(<span class="cm-variable">c</span>));</span></pre> | ||
967 | </div> | ||
968 | <div style="position: relative;"> | ||
969 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
970 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | ||
971 | </div> | ||
972 | <pre class=" CodeMirror-line " | ||
973 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">ofs</span>.<span class="cm-variable">read</span>(<span class="cm-variable">s</span>.<span class="cm-variable">c_str</span>(),<span class="cm-keyword">sizeof</span>(<span class="cm-variable-3">char</span>) <span class="cm-operator">*</span> <span class="cm-variable">s</span>.<span class="cm-variable">length</span>());</span></pre> | ||
974 | </div> | ||
975 | <div style="position: relative;"> | ||
976 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
977 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
978 | </div> | ||
979 | <pre class=" CodeMirror-line " | ||
980 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre> | ||
981 | </div> | ||
982 | <div style="position: relative;"> | ||
983 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
984 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
985 | style="left: 0px; width: 27px;">20</div> | ||
986 | </div> | ||
987 | <pre class=" CodeMirror-line " | ||
988 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
989 | </div> | ||
990 | </div> | ||
991 | </div> | ||
992 | </div> | ||
993 | </div> | ||
994 | </div> | ||
995 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 461px;"></div> | ||
996 | <div class="CodeMirror-gutters" style="height: 461px;"> | ||
997 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
998 | </div> | ||
999 | </div> | ||
1000 | </div> | ||
1001 | </pre> | ||
1002 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | ||
1003 | </div> | ||
1004 | </div> | ||
1005 | </body> | ||
1006 | |||
1007 | </html> \ No newline at end of file | ||
diff --git a/code/fileop(cpp).md b/code/fileop(cpp).md deleted file mode 100644 index 86405c7..0000000 --- a/code/fileop(cpp).md +++ /dev/null | |||
@@ -1,192 +0,0 @@ | |||
1 | [toc] | ||
2 | |||
3 | # 头文件 | ||
4 | |||
5 | C++文件操作头文件 fstream,也就是“文件流”。 | ||
6 | |||
7 | # 对象声明 | ||
8 | |||
9 | ```C++ | ||
10 | ofstream ofs;//执行写操作 | ||
11 | ifstream ifs;//执行读操作 | ||
12 | fstream file;//读写都可以 | ||
13 | ``` | ||
14 | |||
15 | # 文件打开、关闭 | ||
16 | |||
17 | 以下所有内容均假设使用对象名为 file(不论是 ofstream 还是 ifstream/fstream),打开方式为:`file.open(文件路径,打开方式);` | ||
18 | 同时也可以在定义流对象时直接打开: | ||
19 | `ifstream file(文件路径,打开方式)` | ||
20 | 其中,文件路径的参数为 string 类型字符串或 char\*型字符数组。 | ||
21 | | 打开方式 | 解释 | | ||
22 | |:-----------:|:------------:| | ||
23 | |ios::in |读取 | | ||
24 | |ios::out |写入 | | ||
25 | |ios::ate |初始位置:文件尾 | | ||
26 | |ios::app |追加方式写文件 | | ||
27 | |ios::trunc|如果文件存在先删除,再创建| | ||
28 | |ios::binary|二进制方式 | | ||
29 | |||
30 | 文件关闭:`file.close();` | ||
31 | 文件关闭之后流并未删除,只是断开了流到文件的链接,流管理装置仍然保留,因而可以用来再次打开某个文件。此时由于之前使用的内容还储存着,为避免对之后的使用造成影响,应当在文件关闭后使用函数`file.clear()`把整个类全部重置。 | ||
32 | |||
33 | - 注意:文件打开方式可以配合使用,利用 | 操作符。例如,用二进制方式写文件: | ||
34 | `ios::out | ios::binary` | ||
35 | - ios 即 basic_ios,二者互为别名;ios 类是在 ios_base 基础上的派生类。 | ||
36 | - 打开方式可以不写,默认打开方式为`ios::in|ios::out`,以默认模式打开文件进行输出(写入)时,文件长度将自动截短为 0,也就是删除之前内容。 | ||
37 | |||
38 | # 文件操作 | ||
39 | |||
40 | - 由于`ifstream`、`ofstream`、`fstream`等`fstream`中定义的类都是从`iostream`的相应类中派生而来,所以均可使用原来的类的操作方法,并且继承其特性(如 ifs 会和 cin 一样,遇到空格就截断字符串)。一如 C 语言中的 gets/fgets、scanf/fscanf、printf/fprintf。 | ||
41 | |||
42 | # 文本文件 | ||
43 | |||
44 | ## 读取 | ||
45 | |||
46 | 五种方法。例程如下: | ||
47 | |||
48 | ```C++ | ||
49 | #include <iostream> | ||
50 | #include <string> | ||
51 | #include <fstream> | ||
52 | using namespace std; | ||
53 | |||
54 | int main() | ||
55 | { | ||
56 | ifstream ifs; | ||
57 | char buf[1000] = { 0 }; | ||
58 | string s; | ||
59 | ifs.open("test.txt",ios::in); | ||
60 | if(!ifs.is_open()) | ||
61 | { | ||
62 | cout << "文件打开失败!" << endl; | ||
63 | return -1; | ||
64 | } | ||
65 | /*方法一,缺点在于空格即断开*/ | ||
66 | while(ifs >> buf) | ||
67 | { | ||
68 | cout << buf <<endl; | ||
69 | } | ||
70 | /*方法二,缺点同上*/ | ||
71 | while(ifs.getline(buf,sizeof(buf))) | ||
72 | { | ||
73 | cout << buf <<endl; | ||
74 | } | ||
75 | /*方法三,整行读取*/ | ||
76 | while(getline(ifs,s)) | ||
77 | { | ||
78 | cout << buf <<endl; | ||
79 | } | ||
80 | /*方法四,逐个字符读取,太不爽*/ | ||
81 | char c; | ||
82 | while((c = ifs.get()) != EOF) | ||
83 | { | ||
84 | cout<<c; | ||
85 | } | ||
86 | /*方法五,缺点在和cin一样,遇到空格就截断,而不只是换行符*/ | ||
87 | ifs >> buf; | ||
88 | |||
89 | ifs.close(); | ||
90 | ifs.clear(); | ||
91 | return 0; | ||
92 | } | ||
93 | ``` | ||
94 | |||
95 | ## 文件写入 | ||
96 | |||
97 | 格式如下: | ||
98 | `对象名 << 写入的内容;` | ||
99 | 如需换行,在写入内容后加 endl 即可。例程如下: | ||
100 | |||
101 | ```C++ | ||
102 | #include <iostream> | ||
103 | #include <string> | ||
104 | #include <fstream> | ||
105 | using namespace std; | ||
106 | |||
107 | int main() | ||
108 | { | ||
109 | ofstream ofs; | ||
110 | ofs.open("test.txt",ios::out); | ||
111 | if(!ofs.is_open()) | ||
112 | { | ||
113 | cout << "文件打开失败!" << endl; | ||
114 | return -1; | ||
115 | } | ||
116 | ofs << "-How old are you?" << endl; | ||
117 | ofs << "-I'm 21ys old." << endl; | ||
118 | ofs << "-Oh,what a young guy!" << endl; | ||
119 | ofs << "-Thanks." <<endl; | ||
120 | ofs.close(); | ||
121 | return 0; | ||
122 | } | ||
123 | ``` | ||
124 | |||
125 | ## 总结 | ||
126 | |||
127 | 读文件可以利用 ifstream 或者 fstream 类。 | ||
128 | 利用 is_open 函数可以判断文件是否打开成功。 | ||
129 | 操作完毕,要关闭文件。 | ||
130 | |||
131 | # 二进制文件 | ||
132 | |||
133 | 以二进制形式读写文件。 | ||
134 | 打开方式需要指定为`ios::binary`。 | ||
135 | |||
136 | ## 读取 | ||
137 | |||
138 | 利用流对象调用成员函数`read`。 | ||
139 | 函数原型:`istream& read(char* buffer, int len)` | ||
140 | 参数解释:字符指针 buffer 指向内存中一段存储空间。len 是读写的字节数。 | ||
141 | 例程如下: | ||
142 | |||
143 | ```c++ | ||
144 | #include <iostream> | ||
145 | #include <string> | ||
146 | #include <fstream> | ||
147 | using namespace std; | ||
148 | |||
149 | int main() | ||
150 | { | ||
151 | ifstream ifs; | ||
152 | int a[10]; | ||
153 | ifs.open("test.bin",ios::in | ios::binary); | ||
154 | if(!ifs.is_open()) | ||
155 | { | ||
156 | cout << "文件打开失败!" << endl; | ||
157 | return -1; | ||
158 | } | ||
159 | ifs.read((char*)a, sizeof(int) * 10); | ||
160 | return 0; | ||
161 | } | ||
162 | ``` | ||
163 | |||
164 | ## 写入 | ||
165 | |||
166 | 使用流对象成员函数`write`。 | ||
167 | 函数原型:`ostream& write(const char* buffer, int len)` | ||
168 | 参数解释:字符指针 buffer 指向内存中一段存储空间。len 是读写的字节数。 | ||
169 | 例程如下: | ||
170 | |||
171 | ```c++ | ||
172 | #include <iostream> | ||
173 | #include <string> | ||
174 | #include <fstream> | ||
175 | using namespace std; | ||
176 | |||
177 | int main() | ||
178 | { | ||
179 | ofstream ofs; | ||
180 | int c=-3; | ||
181 | string s="Long Live the People!"; | ||
182 | ifs.open("test.bin",ios::in | ios::binary); | ||
183 | if(!ofs.is_open()) | ||
184 | { | ||
185 | cout << "文件打开失败!" << endl; | ||
186 | return -1; | ||
187 | } | ||
188 | ofs.read((char*)&c,sizeof(c)); | ||
189 | ofs.read(s.c_str(),sizeof(char) * s.length()); | ||
190 | return 0; | ||
191 | } | ||
192 | ``` | ||
diff --git a/code/highlight.html b/code/highlight.html index 840a3fb..e2dee0d 100644 --- a/code/highlight.html +++ b/code/highlight.html | |||
@@ -5,6 +5,7 @@ | |||
5 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
6 | <title>我的代码块</title> | 6 | <title>我的代码块</title> |
7 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 7 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
8 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
8 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 9 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
9 | </head> | 10 | </head> |
10 | 11 | ||
diff --git a/code/index.html b/code/index.html index 388c785..ec6ecce 100644 --- a/code/index.html +++ b/code/index.html | |||
@@ -1,1646 +1,236 @@ | |||
1 | <!doctype html> | 1 | <!DOCTYPE html> |
2 | <html> | 2 | <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> |
3 | 3 | ||
4 | <head> | 4 | <head> |
5 | <meta charset='UTF-8'> | 5 | <meta charset="utf-8" /> |
6 | <meta name='viewport' content='width=device-width initial-scale=1'> | 6 | <meta name="generator" content="pandoc" /> |
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | ||
7 | <title>我的实用代码</title> | 8 | <title>我的实用代码</title> |
8 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/github.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
9 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
10 | </head> | 12 | </head> |
11 | 13 | ||
12 | <body class='typora-export os-windows'> | 14 | <body> |
13 | <div class='typora-export-content'> | 15 | <div class="pandoc"> |
14 | <div id='write' class=''> | 16 | <div class="main"> |
15 | <div class='md-toc' mdtype='toc'> | 17 | <p class="title">我的实用代码</p> |
16 | <p class="md-toc-content" role="list"><span role="listitem" class="md-toc-item md-toc-h1" | 18 | <p>这里是英(C)语(yǔ)科(yán)听力部分。该部分有第一、第二两节。</p> |
17 | data-ref="n44"><a class="md-toc-inner" href="#光标隐藏函数">光标隐藏函数</a></span><span role="listitem" | 19 | <p>请注意,回答听力部分时,请先将答案写在试卷上,听力部分结束前,你将有两分钟的时间将试卷上的答案转移到答题卡上。</p> |
18 | class="md-toc-item md-toc-h1" data-ref="n46"><a class="md-toc-inner" | 20 | <p>听力考试,现在开始!</p> |
19 | href="#showbytes">show_bytes</a></span><span role="listitem" class="md-toc-item md-toc-h1" | 21 | <h1 id="光标隐藏函数">光标隐藏函数</h1> |
20 | data-ref="n48"><a class="md-toc-inner" href="#界面设计和上色">界面设计和上色</a></span><span role="listitem" | 22 | <pre><code>void HideCursor(void) |
21 | class="md-toc-item md-toc-h1" data-ref="n53"><a class="md-toc-inner" | 23 | { |
22 | href="#关于音乐效果">关于音乐效果</a></span><span role="listitem" class="md-toc-item md-toc-h1" | 24 | CONSOLE_CURSOR_INFO cursor_info = {1, 0}; |
23 | data-ref="n56"><a class="md-toc-inner" href="#震动心形设计">震动心形设计</a></span><span role="listitem" | 25 | SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); |
24 | class="md-toc-item md-toc-h1" data-ref="n60"><a class="md-toc-inner" | 26 | }</code></pre> |
25 | href="#给代码加行号的代码">给代码加行号的代码</a></span></p> | 27 | <h1 id="show_bytes">show_bytes</h1> |
26 | </div> | 28 | <pre><code>#include <bits/stdc++.h> |
27 | <p><span>这里是英(C)语(yǔ)科(yán)听力部分。该部分有第一、第二两节。</span></p> | 29 | using namespace std; |
28 | <p><span>请注意,回答听力部分时,请先将答案写在试卷上,听力部分结束前,你将有两分钟的时间将试卷上的答案转移到答题卡上。</span></p> | 30 | typedef unsigned char* bite_pointer; |
29 | <p><span>听力考试,现在开始!</span></p> | 31 | typedef int T;//数据类型为int,可更改 |
30 | <h1 id='光标隐藏函数'><span>光标隐藏函数</span></h1> | 32 | void show_bites(bite_pointer p,size_t len) |
31 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" | 33 | { |
32 | lang="c"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | 34 | size_t i; |
33 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | 35 | cout<<"In machine order:"; |
34 | <div>5</div> | 36 | for(i=0;i<len;i++) |
35 | </div> | 37 | { |
36 | </div> | 38 | printf("%.2x ",p[i]); |
37 | <div class="CodeMirror-measure"></div> | 39 | } |
38 | <div style="position: relative; z-index: 1;"></div> | 40 | printf("\n"); |
39 | <div class="CodeMirror-code" role="presentation" style=""> | 41 | cout<<"In person order: "; |
40 | <div class="CodeMirror-activeline" style="position: relative;"> | 42 | for(i=len-1;i>0;i--) |
41 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | 43 | { |
42 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" | 44 | printf("%.2x ",p[i]); |
43 | style="left: -28px; width: 28px;"></div> | 45 | } |
44 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"> | 46 | printf("%.2x ",p[i]); |
45 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | 47 | printf("\n"); |
46 | style="left: 0px; width: 19px;">1</div> | 48 | } |
47 | </div> | 49 | int main() |
48 | <pre class=" CodeMirror-line " | 50 | { |
49 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">HideCursor</span>(<span class="cm-variable-3">void</span>)</span></pre> | 51 | int a; |
50 | </div> | 52 | cout<<"Please input the data in type \"int\":"; |
51 | <div style="position: relative;"> | 53 | cin>>a; |
52 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | 54 | show_bites((bite_pointer)&a,sizeof(T)); |
53 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div> | 55 | return 0; |
54 | </div> | 56 | }</code></pre> |
55 | <pre class=" CodeMirror-line " | 57 | <h1 id="界面设计和上色">界面设计和上色</h1> |
56 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | 58 | <p>注意:<strong>本内容请勿改动任何参数!</strong></p> |
57 | </div> | 59 | <pre><code>#include <windows.h> |
58 | <div style="position: relative;"> | 60 | #include <conio.h> |
59 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | 61 | #include <time.h> |
60 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div> | 62 | |
61 | </div> | 63 | int wide=60,high=30;//宏常量定义,数据可变 |
62 | <pre class=" CodeMirror-line " | 64 | HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);//写在主函数或调用函数内部,用于定义hout并进行初始化 |
63 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">CONSOLE_CURSOR_INFO</span> <span class="cm-variable">cursor_info</span> <span class="cm-operator">=</span> {<span class="cm-number">1</span>, <span class="cm-number">0</span>};</span></pre> | 65 | system("mode con cols=80 lines=40 ");//运行框大小限制 |
64 | </div> | 66 | |
65 | <div style="position: relative;"> | 67 | void gotoxy(HANDLE hout,int x,int y) |
66 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | 68 | { |
67 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div> | 69 | HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); |
68 | </div> | 70 | COORD pos; |
69 | <pre class=" CodeMirror-line " | 71 | pos.X = x; |
70 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">SetConsoleCursorInfo</span>(<span class="cm-variable">GetStdHandle</span>(<span class="cm-variable">STD_OUTPUT_HANDLE</span>), <span class="cm-operator">&</span><span class="cm-variable">cursor_info</span>);</span></pre> | 72 | pos.Y = y; |
71 | </div> | 73 | SetConsoleCursorPosition(hout,pos); |
72 | <div style="position: relative;"> | 74 | } |
73 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | 75 | int color(int c)//设置颜色 |
74 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | 76 | { |
75 | style="left: 0px; width: 19px;">5</div> | 77 | SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c); |
76 | </div> | 78 | return 0; |
77 | <pre class=" CodeMirror-line " | 79 | }//颜色有若干种 |
78 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | 80 | //两个调用函数</code></pre> |
79 | </div> | 81 | <p>设置某句子的位置用<code>gotoxy(hout,wide*k,high*m)</code>,就是在 wide 的 k 倍,high 的 m 倍的位置。 |
80 | </div> | 82 | 句子上色用<code>color(c)</code>,c 为指定颜色序号。 |
81 | </div> | 83 | 输出后的停顿用<code>void Sleep(int t)</code>函数,在<code><windows.h></code>中,t 代表暂停的毫秒数。 使用时每个句子前都要用 gotoxy |
82 | </div> | 84 | 指定位置,用 color 上色。 合起来如下:</p> |
83 | </div> | 85 | <pre><code> gotoxy(hout,wide/5,high/6); |
84 | </div> | 86 | color(6); |
85 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 115px;"></div> | 87 | printf("本计算器仅支持5个及以下的矩阵,分别名为A~E(大写)。"); |
86 | <div class="CodeMirror-gutters" style="height: 115px;"> | 88 | Sleep(200); |
87 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div> | 89 | gotoxy(hout,wide/5,high/6+1); |
88 | </div> | 90 | color(6); |
89 | </div> | 91 | printf("每个矩阵阶数不超过5*5。"); |
90 | </div> | 92 | Sleep(200);</code></pre> |
91 | </pre> | 93 | <h1 id="关于音乐效果">关于音乐效果</h1> |
92 | <h1 id='showbytes'><span>show_bytes</span></h1> | 94 | <pre><code>#include<windows.h> |
93 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="cpp" | 95 | #include<mmsystem.h> |
94 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="cpp"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | 96 | #pragma comment(lib."Winmm.lib") //头文件 |
95 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | 97 | PlaySound(TEXT("音乐名.wav"),NULL,SND_FILENAME | SND_ASYNC | SND_LOOP);//开始播放 |
96 | <div>29</div> | 98 | PlaySound(NULL,NULL,SND_FILENAME);//结束播放</code></pre> |
97 | </div> | 99 | <p>注意:音频必须使用<strong>wav</strong>格式,必须放在<strong>跟代码同一个文件夹</strong>,如果不然,音乐名处<strong>应当使用其绝对地址或相对地址</strong>。 |
98 | </div> | 100 | </p> |
99 | <div class="CodeMirror-measure"></div> | 101 | <h1 id="震动心形设计">震动心形设计</h1> |
100 | <div style="position: relative; z-index: 1;"></div> | 102 | <pre><code>#define I 20 |
101 | <div class="CodeMirror-code" role="presentation" style=""> | 103 | #define R 340 |
102 | <div class="CodeMirror-activeline" style="position: relative;"> | 104 | |
103 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | 105 | int wide=80,high=40;//宏常量定义,数据可变 |
104 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | 106 | system("title xxx");//运行框名称修改,主函数第一句 |
105 | </div> | 107 | system("mode con cols=80 lines=40 ");//运行框大小限制 |
106 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | 108 | |
107 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | 109 | void draw_color()//整体颜色震动效果函数 |
108 | style="left: 0px; width: 27px;">1</div> | 110 | { |
109 | </div> | 111 | char cl[20]; |
110 | <pre class=" CodeMirror-line " | 112 | srand((unsigned int)time(NULL)); |
111 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <bits/stdc++.h></span></span></pre> | 113 | int k = rand() % strlen(back_color); |
112 | </div> | 114 | strcpy(cl, Color); |
113 | <div style="position: relative;"> | 115 | cl[len] = back_color[k]; |
114 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 116 | srand((unsigned int)time(NULL)); |
115 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | 117 | k = rand() % strlen(font_color); |
116 | </div> | 118 | cl[len + 1] = font_color[k]; |
117 | <pre class=" CodeMirror-line " | 119 | cl[len + 2] = '\0'; |
118 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">using</span> <span class="cm-keyword">namespace</span> <span class="cm-def">std</span>;</span></pre> | 120 | system(cl); |
119 | </div> | 121 | }</code></pre> |
120 | <div style="position: relative;"> | 122 | <p>颜色震动使用方法实例:</p> |
121 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 123 | <pre><code>for(i=0;i<6;i++,lower+=3) |
122 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | 124 | { |
123 | </div> | 125 | puts(data[i+15]); |
124 | <pre class=" CodeMirror-line " | 126 | for(j=0;j<wait;j++) |
125 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">typedef</span> <span class="cm-variable-3">unsigned</span> <span class="cm-variable-3">char*</span> <span class="cm-variable">bite_pointer</span>;</span></pre> | 127 | { |
126 | </div> | 128 | draw_color(); |
127 | <div style="position: relative;"> | 129 | Sleep(200); |
128 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 130 | } |
129 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | 131 | Sleep(200); |
130 | </div> | 132 | } |
131 | <pre class=" CodeMirror-line " | 133 | void draw_heart(int wait)//心形设计函数,传入参数为0即可 |
132 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">typedef</span> <span class="cm-variable-3">int</span> <span class="cm-variable">T</span>;<span class="cm-comment">//数据类型为int,可更改</span></span></pre> | 134 | { |
133 | </div> | 135 | int i,j,e,a; |
134 | <div style="position: relative;"> | 136 | for(i=1,a=I;i<I/2;i++,a--) |
135 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 137 | { |
136 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | 138 | for(j=(int) ( I-sqrt(I*I-(a-i)*(a-i)) );j>0;j--) |
137 | </div> | 139 | { |
138 | <pre class=" CodeMirror-line " | 140 | printf(" "); |
139 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">show_bites</span>(<span class="cm-variable">bite_pointer</span> <span class="cm-variable">p</span>,<span class="cm-variable-3">size_t</span> <span class="cm-variable">len</span>)</span></pre> | 141 | } |
140 | </div> | 142 | for(e=1;e<=2*sqrt(I*I-(a-i)*(a-i));e++) |
141 | <div style="position: relative;"> | 143 | { |
142 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 144 | printf("\3"); |
143 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | 145 | } |
144 | </div> | 146 | for(j=(int)( 2*( I-sqrt(I*I-(a-i)*(a-i)) ) );j>0;j--) |
145 | <pre class=" CodeMirror-line " | 147 | { |
146 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | 148 | printf(" "); |
147 | </div> | 149 | } |
148 | <div style="position: relative;"> | 150 | for(e=1;e<=2*sqrt(I*I-(a-i)*(a-i));e++) |
149 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 151 | { |
150 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | 152 | printf("\3"); |
151 | </div> | 153 | } |
152 | <pre class=" CodeMirror-line " | 154 | printf("\n"); |
153 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">size_t</span> <span class="cm-variable">i</span>;</span></pre> | 155 | if(wait&&i%2) |
154 | </div> | 156 | { |
155 | <div style="position: relative;"> | 157 | draw_color(); |
156 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 158 | Sleep(80); |
157 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | 159 | } |
158 | </div> | 160 | } |
159 | <pre class=" CodeMirror-line " | 161 | for(i=1;i<80;i++) |
160 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-string">"In machine order:"</span>;</span></pre> | 162 | { |
161 | </div> | 163 | if(i==20) |
162 | <div style="position: relative;"> | 164 | { |
163 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 165 | for(int j=0;j<40;j++) |
164 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | 166 | { |
165 | </div> | 167 | printf("\3"); |
166 | <pre class=" CodeMirror-line " | 168 | } |
167 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">0</span>;<span class="cm-variable">i</span><span class="cm-operator"><</span><span class="cm-variable">len</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre> | 169 | i+=40; |
168 | </div> | 170 | } |
169 | <div style="position: relative;"> | 171 | printf("\3"); |
170 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 172 | } |
171 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | 173 | printf("\n"); |
172 | style="left: 0px; width: 27px;">10</div> | 174 | for(i=1;i<=R/2;i++) |
173 | </div> | 175 | { |
174 | <pre class=" CodeMirror-line " | 176 | if(i%2||i%3) |
175 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | 177 | { |
176 | </div> | 178 | continue; |
177 | <div style="position: relative;"> | 179 | } |
178 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 180 | for(j=(int) ( R-sqrt(R*R-i*i) );j>0;j--) |
179 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | 181 | { |
180 | </div> | 182 | printf(" "); |
181 | <pre class=" CodeMirror-line " | 183 | } |
182 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"%.2x "</span>,<span class="cm-variable">p</span>[<span class="cm-variable">i</span>]);</span></pre> | 184 | for(e=1;e<=2*( sqrt(R*R-i*i) - (R-2*I) );e++) |
183 | </div> | 185 | { |
184 | <div style="position: relative;"> | 186 | printf("\3"); |
185 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 187 | } |
186 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | 188 | printf("\n"); |
187 | </div> | 189 | if(wait) |
188 | <pre class=" CodeMirror-line " | 190 | { |
189 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | 191 | draw_color(); |
190 | </div> | 192 | Sleep(80); |
191 | <div style="position: relative;"> | 193 | } |
192 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 194 | } |
193 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | 195 | }</code></pre> |
194 | </div> | 196 | <h1 id="给代码加行号的代码">给代码加行号的代码</h1> |
195 | <pre class=" CodeMirror-line " | 197 | <pre><code>#include<stdio.h> |
196 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"\n"</span>);</span></pre> | 198 | |
197 | </div> | 199 | int main(void) |
198 | <div style="position: relative;"> | 200 | { |
199 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 201 | FILE *fpIn; |
200 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | 202 | // 输入文件的指针 |
201 | </div> | 203 | FILE *fpOut; |
202 | <pre class=" CodeMirror-line " | 204 | // 输出文件的指针 |
203 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-string">"In person order: "</span>;</span></pre> | 205 | char str[1000]; |
204 | </div> | 206 | // 用来存储从文件中读取出的”一行“字符串信息 |
205 | <div style="position: relative;"> | 207 | int row = 1; |
206 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 208 | fpIn = fopen("文件名.cpp", "r"); |
207 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | 209 | /* 以只读和文本格式打开需要的.cpp文件 |
208 | </div> | 210 | *这里的文件名无所谓大小写 |
209 | <pre class=" CodeMirror-line " | 211 | */ |
210 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-variable">len</span><span class="cm-operator">-</span><span class="cm-number">1</span>;<span class="cm-variable">i</span><span class="cm-operator">></span><span class="cm-number">0</span>;<span class="cm-variable">i</span><span class="cm-operator">--</span>)</span></pre> | 212 | fpOut = fopen("文件名.txt", "w"); |
211 | </div> | 213 | // 以创建方式(也叫写方式)打开文件名.txt文件 |
212 | <div style="position: relative;"> | 214 | fgets(str, 81, fpIn); |
213 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 215 | /* 从文件中读取一行信息,保存到str数组中。 |
214 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | 216 | *这里要注意的是这个81, |
215 | </div> | 217 | *一般情况下,编写文本格式文件的人,都习惯遇到行尾就敲回车, |
216 | <pre class=" CodeMirror-line " | 218 | *所以,一般情况下,文本文件一行最多80个字符。 |
217 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | 219 | *如果,一行不够80个字符,这个函数会自动只读到'\n'就结束了。 |
218 | </div> | 220 | */ |
219 | <div style="position: relative;"> | 221 | while(!feof(fpIn)) |
220 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 222 | { // 判断上一次fgets()是否正常(即,没有遇到文件尾部) |
221 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | 223 | fprintf(fpOut, "%4d %s", row, str); |
222 | </div> | 224 | // 在读入的每一行信息前,加入0000到9999的行号(应该够用了吧),呵呵呵呵 |
223 | <pre class=" CodeMirror-line " | 225 | row++; // 行号加一 |
224 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"%.2x "</span>,<span class="cm-variable">p</span>[<span class="cm-variable">i</span>]);</span></pre> | 226 | fgets(str, 81, fpIn); // 读取下一行 |
225 | </div> | 227 | } |
226 | <div style="position: relative;"> | 228 | fclose(fpIn); // 关闭文件 |
227 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | 229 | fclose(fpOut); |
228 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | 230 | }</code></pre> |
229 | </div> | 231 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> |
230 | <pre class=" CodeMirror-line " | ||
231 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
232 | </div> | ||
233 | <div style="position: relative;"> | ||
234 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
235 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
236 | </div> | ||
237 | <pre class=" CodeMirror-line " | ||
238 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"%.2x "</span>,<span class="cm-variable">p</span>[<span class="cm-variable">i</span>]);</span></pre> | ||
239 | </div> | ||
240 | <div style="position: relative;"> | ||
241 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
242 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
243 | style="left: 0px; width: 27px;">20</div> | ||
244 | </div> | ||
245 | <pre class=" CodeMirror-line " | ||
246 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"\n"</span>);</span></pre> | ||
247 | </div> | ||
248 | <div style="position: relative;"> | ||
249 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
250 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div> | ||
251 | </div> | ||
252 | <pre class=" CodeMirror-line " | ||
253 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
254 | </div> | ||
255 | <div style="position: relative;"> | ||
256 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
257 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div> | ||
258 | </div> | ||
259 | <pre class=" CodeMirror-line " | ||
260 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>()</span></pre> | ||
261 | </div> | ||
262 | <div style="position: relative;"> | ||
263 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
264 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div> | ||
265 | </div> | ||
266 | <pre class=" CodeMirror-line " | ||
267 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
268 | </div> | ||
269 | <div style="position: relative;"> | ||
270 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
271 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div> | ||
272 | </div> | ||
273 | <pre class=" CodeMirror-line " | ||
274 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">int</span> <span class="cm-variable">a</span>;</span></pre> | ||
275 | </div> | ||
276 | <div style="position: relative;"> | ||
277 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
278 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div> | ||
279 | </div> | ||
280 | <pre class=" CodeMirror-line " | ||
281 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cout</span><span class="cm-operator"><<</span><span class="cm-string">"Please input the data in type \"int\":"</span>;</span></pre> | ||
282 | </div> | ||
283 | <div style="position: relative;"> | ||
284 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
285 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div> | ||
286 | </div> | ||
287 | <pre class=" CodeMirror-line " | ||
288 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">cin</span><span class="cm-operator">>></span><span class="cm-variable">a</span>;</span></pre> | ||
289 | </div> | ||
290 | <div style="position: relative;"> | ||
291 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
292 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div> | ||
293 | </div> | ||
294 | <pre class=" CodeMirror-line " | ||
295 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">show_bites</span>((<span class="cm-variable">bite_pointer</span>)<span class="cm-operator">&</span><span class="cm-variable">a</span>,<span class="cm-keyword">sizeof</span>(<span class="cm-variable">T</span>));</span></pre> | ||
296 | </div> | ||
297 | <div style="position: relative;"> | ||
298 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
299 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div> | ||
300 | </div> | ||
301 | <pre class=" CodeMirror-line " | ||
302 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre> | ||
303 | </div> | ||
304 | <div style="position: relative;"> | ||
305 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
306 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
307 | style="left: 0px; width: 27px;">29</div> | ||
308 | </div> | ||
309 | <pre class=" CodeMirror-line " | ||
310 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
311 | </div> | ||
312 | </div> | ||
313 | </div> | ||
314 | </div> | ||
315 | </div> | ||
316 | </div> | ||
317 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 668px;"></div> | ||
318 | <div class="CodeMirror-gutters" style="height: 668px;"> | ||
319 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
320 | </div> | ||
321 | </div> | ||
322 | </div> | ||
323 | </pre> | ||
324 | <h1 id='界面设计和上色'><span>界面设计和上色</span></h1> | ||
325 | <p><span>注意:</span><strong><span>本内容请勿改动任何参数!</span></strong></p> | ||
326 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c" | ||
327 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
328 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
329 | <div>22</div> | ||
330 | </div> | ||
331 | </div> | ||
332 | <div class="CodeMirror-measure"></div> | ||
333 | <div style="position: relative; z-index: 1;"></div> | ||
334 | <div class="CodeMirror-code" role="presentation" style=""> | ||
335 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
336 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
337 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
338 | </div> | ||
339 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
340 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
341 | style="left: 0px; width: 27px;">1</div> | ||
342 | </div> | ||
343 | <pre class=" CodeMirror-line " | ||
344 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <windows.h> </span></span></pre> | ||
345 | </div> | ||
346 | <div style="position: relative;"> | ||
347 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
348 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
349 | </div> | ||
350 | <pre class=" CodeMirror-line " | ||
351 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <conio.h></span></span></pre> | ||
352 | </div> | ||
353 | <div style="position: relative;"> | ||
354 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
355 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
356 | </div> | ||
357 | <pre class=" CodeMirror-line " | ||
358 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include <time.h></span></span></pre> | ||
359 | </div> | ||
360 | <div style="position: relative;"> | ||
361 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
362 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
363 | </div> | ||
364 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
365 | </span></span></pre> | ||
366 | </div> | ||
367 | <div style="position: relative;"> | ||
368 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
369 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
370 | </div> | ||
371 | <pre class=" CodeMirror-line " | ||
372 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">wide</span><span class="cm-operator">=</span><span class="cm-number">60</span>,<span class="cm-variable">high</span><span class="cm-operator">=</span><span class="cm-number">30</span>;<span class="cm-comment">//宏常量定义,数据可变</span></span></pre> | ||
373 | </div> | ||
374 | <div style="position: relative;"> | ||
375 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
376 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
377 | </div> | ||
378 | <pre class=" CodeMirror-line " | ||
379 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">HANDLE</span> <span class="cm-variable">hout</span><span class="cm-operator">=</span><span class="cm-variable">GetStdHandle</span>(<span class="cm-variable">STD_OUTPUT_HANDLE</span>);<span class="cm-comment">//写在主函数或调用函数内部,用于定义hout并进行初始化</span></span></pre> | ||
380 | </div> | ||
381 | <div style="position: relative;"> | ||
382 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
383 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
384 | </div> | ||
385 | <pre class=" CodeMirror-line " | ||
386 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">system</span>(<span class="cm-string">"mode con cols=80 lines=40 "</span>);<span class="cm-comment">//运行框大小限制 </span></span></pre> | ||
387 | </div> | ||
388 | <div style="position: relative;"> | ||
389 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
390 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
391 | </div> | ||
392 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
393 | </span></span></pre> | ||
394 | </div> | ||
395 | <div style="position: relative;"> | ||
396 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
397 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
398 | </div> | ||
399 | <pre class=" CodeMirror-line " | ||
400 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">gotoxy</span>(<span class="cm-variable">HANDLE</span> <span class="cm-variable">hout</span>,<span class="cm-variable-3">int</span> <span class="cm-variable">x</span>,<span class="cm-variable-3">int</span> <span class="cm-variable">y</span>)</span></pre> | ||
401 | </div> | ||
402 | <div style="position: relative;"> | ||
403 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
404 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
405 | style="left: 0px; width: 27px;">10</div> | ||
406 | </div> | ||
407 | <pre class=" CodeMirror-line " | ||
408 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
409 | </div> | ||
410 | <div style="position: relative;"> | ||
411 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
412 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
413 | </div> | ||
414 | <pre class=" CodeMirror-line " | ||
415 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">HANDLE</span> <span class="cm-variable">handle</span> <span class="cm-operator">=</span> <span class="cm-variable">GetStdHandle</span>(<span class="cm-variable">STD_OUTPUT_HANDLE</span>);</span></pre> | ||
416 | </div> | ||
417 | <div style="position: relative;"> | ||
418 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
419 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
420 | </div> | ||
421 | <pre class=" CodeMirror-line " | ||
422 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">COORD</span> <span class="cm-variable">pos</span>;</span></pre> | ||
423 | </div> | ||
424 | <div style="position: relative;"> | ||
425 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
426 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
427 | </div> | ||
428 | <pre class=" CodeMirror-line " | ||
429 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">pos</span>.<span class="cm-variable">X</span> <span class="cm-operator">=</span> <span class="cm-variable">x</span>;</span></pre> | ||
430 | </div> | ||
431 | <div style="position: relative;"> | ||
432 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
433 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
434 | </div> | ||
435 | <pre class=" CodeMirror-line " | ||
436 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">pos</span>.<span class="cm-variable">Y</span> <span class="cm-operator">=</span> <span class="cm-variable">y</span>;</span></pre> | ||
437 | </div> | ||
438 | <div style="position: relative;"> | ||
439 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
440 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
441 | </div> | ||
442 | <pre class=" CodeMirror-line " | ||
443 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">SetConsoleCursorPosition</span>(<span class="cm-variable">hout</span>,<span class="cm-variable">pos</span>); </span></pre> | ||
444 | </div> | ||
445 | <div style="position: relative;"> | ||
446 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
447 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
448 | </div> | ||
449 | <pre class=" CodeMirror-line " | ||
450 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
451 | </div> | ||
452 | <div style="position: relative;"> | ||
453 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
454 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
455 | </div> | ||
456 | <pre class=" CodeMirror-line " | ||
457 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">color</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">c</span>)<span class="cm-comment">//设置颜色 </span></span></pre> | ||
458 | </div> | ||
459 | <div style="position: relative;"> | ||
460 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
461 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | ||
462 | </div> | ||
463 | <pre class=" CodeMirror-line " | ||
464 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
465 | </div> | ||
466 | <div style="position: relative;"> | ||
467 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
468 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
469 | </div> | ||
470 | <pre class=" CodeMirror-line " | ||
471 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">SetConsoleTextAttribute</span>(<span class="cm-variable">GetStdHandle</span>(<span class="cm-variable">STD_OUTPUT_HANDLE</span>),<span class="cm-variable">c</span>);</span></pre> | ||
472 | </div> | ||
473 | <div style="position: relative;"> | ||
474 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
475 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
476 | style="left: 0px; width: 27px;">20</div> | ||
477 | </div> | ||
478 | <pre class=" CodeMirror-line " | ||
479 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">return</span> <span class="cm-number">0</span>;</span></pre> | ||
480 | </div> | ||
481 | <div style="position: relative;"> | ||
482 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
483 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div> | ||
484 | </div> | ||
485 | <pre class=" CodeMirror-line " | ||
486 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}<span class="cm-comment">//颜色有若干种</span></span></pre> | ||
487 | </div> | ||
488 | <div style="position: relative;"> | ||
489 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
490 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
491 | style="left: 0px; width: 27px;">22</div> | ||
492 | </div> | ||
493 | <pre class=" CodeMirror-line " | ||
494 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-comment">//两个调用函数</span></span></pre> | ||
495 | </div> | ||
496 | </div> | ||
497 | </div> | ||
498 | </div> | ||
499 | </div> | ||
500 | </div> | ||
501 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 507px;"></div> | ||
502 | <div class="CodeMirror-gutters" style="height: 507px;"> | ||
503 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
504 | </div> | ||
505 | </div> | ||
506 | </div> | ||
507 | </pre> | ||
508 | <p><span>设置某句子的位置用</span><code>gotoxy(hout,wide*k,high*m)</code><span>,就是在wide的k倍,high的m倍的位置。</span> | ||
509 | <span>句子上色用</span><code>color(c)</code><span>,c为指定颜色序号。</span> | ||
510 | <span>输出后的停顿用</span><code>void Sleep(int t)</code><span>函数,在</span><code><windows.h></code><span>中,t代表暂停的毫秒数。</span> | ||
511 | <span>使用时每个句子前都要用gotoxy指定位置,用color上色。</span> | ||
512 | <span>合起来如下:</span> | ||
513 | </p> | ||
514 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" | ||
515 | lang="c"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
516 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
517 | <div>8</div> | ||
518 | </div> | ||
519 | </div> | ||
520 | <div class="CodeMirror-measure"></div> | ||
521 | <div style="position: relative; z-index: 1;"></div> | ||
522 | <div class="CodeMirror-code" role="presentation" style=""> | ||
523 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
524 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
525 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"> | ||
526 | </div> | ||
527 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"> | ||
528 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
529 | style="left: 0px; width: 19px;">1</div> | ||
530 | </div> | ||
531 | <pre class=" CodeMirror-line " | ||
532 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">gotoxy</span>(<span class="cm-variable">hout</span>,<span class="cm-variable">wide</span><span class="cm-operator">/</span><span class="cm-number">5</span>,<span class="cm-variable">high</span><span class="cm-operator">/</span><span class="cm-number">6</span>);</span></pre> | ||
533 | </div> | ||
534 | <div style="position: relative;"> | ||
535 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
536 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div> | ||
537 | </div> | ||
538 | <pre class=" CodeMirror-line " | ||
539 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">color</span>(<span class="cm-number">6</span>);</span></pre> | ||
540 | </div> | ||
541 | <div style="position: relative;"> | ||
542 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
543 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div> | ||
544 | </div> | ||
545 | <pre class=" CodeMirror-line " | ||
546 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"本计算器仅支持5个及以下的矩阵,分别名为A~E(大写)。"</span>);</span></pre> | ||
547 | </div> | ||
548 | <div style="position: relative;"> | ||
549 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
550 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div> | ||
551 | </div> | ||
552 | <pre class=" CodeMirror-line " | ||
553 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">Sleep</span>(<span class="cm-number">200</span>);</span></pre> | ||
554 | </div> | ||
555 | <div style="position: relative;"> | ||
556 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
557 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">5</div> | ||
558 | </div> | ||
559 | <pre class=" CodeMirror-line " | ||
560 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">gotoxy</span>(<span class="cm-variable">hout</span>,<span class="cm-variable">wide</span><span class="cm-operator">/</span><span class="cm-number">5</span>,<span class="cm-variable">high</span><span class="cm-operator">/</span><span class="cm-number">6</span><span class="cm-operator">+</span><span class="cm-number">1</span>);</span></pre> | ||
561 | </div> | ||
562 | <div style="position: relative;"> | ||
563 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
564 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">6</div> | ||
565 | </div> | ||
566 | <pre class=" CodeMirror-line " | ||
567 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">color</span>(<span class="cm-number">6</span>);</span></pre> | ||
568 | </div> | ||
569 | <div style="position: relative;"> | ||
570 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
571 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">7</div> | ||
572 | </div> | ||
573 | <pre class=" CodeMirror-line " | ||
574 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"每个矩阵阶数不超过5*5。"</span>);</span></pre> | ||
575 | </div> | ||
576 | <div style="position: relative;"> | ||
577 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
578 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
579 | style="left: 0px; width: 19px;">8</div> | ||
580 | </div> | ||
581 | <pre class=" CodeMirror-line " | ||
582 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">Sleep</span>(<span class="cm-number">200</span>);</span></pre> | ||
583 | </div> | ||
584 | </div> | ||
585 | </div> | ||
586 | </div> | ||
587 | </div> | ||
588 | </div> | ||
589 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 184px;"></div> | ||
590 | <div class="CodeMirror-gutters" style="height: 184px;"> | ||
591 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div> | ||
592 | </div> | ||
593 | </div> | ||
594 | </div> | ||
595 | </pre> | ||
596 | <h1 id='关于音乐效果'><span>关于音乐效果</span></h1> | ||
597 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" | ||
598 | lang="c"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 36px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 28px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
599 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
600 | <div>5</div> | ||
601 | </div> | ||
602 | </div> | ||
603 | <div class="CodeMirror-measure"></div> | ||
604 | <div style="position: relative; z-index: 1;"></div> | ||
605 | <div class="CodeMirror-code" role="presentation" style=""> | ||
606 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
607 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
608 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -28px; width: 28px;"> | ||
609 | </div> | ||
610 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -28px;"> | ||
611 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
612 | style="left: 0px; width: 19px;">1</div> | ||
613 | </div> | ||
614 | <pre class=" CodeMirror-line " | ||
615 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include<windows.h></span></span></pre> | ||
616 | </div> | ||
617 | <div style="position: relative;"> | ||
618 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
619 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">2</div> | ||
620 | </div> | ||
621 | <pre class=" CodeMirror-line " | ||
622 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include<mmsystem.h></span></span></pre> | ||
623 | </div> | ||
624 | <div style="position: relative;"> | ||
625 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
626 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">3</div> | ||
627 | </div> | ||
628 | <pre class=" CodeMirror-line " | ||
629 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#pragma comment(lib."Winmm.lib") </span><span class="cm-comment">//头文件</span></span></pre> | ||
630 | </div> | ||
631 | <div style="position: relative;"> | ||
632 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
633 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 19px;">4</div> | ||
634 | </div> | ||
635 | <pre class=" CodeMirror-line " | ||
636 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">PlaySound</span>(<span class="cm-variable">TEXT</span>(<span class="cm-string">"音乐名.wav"</span>),<span class="cm-variable">NULL</span>,<span class="cm-variable">SND_FILENAME</span> <span class="cm-operator">|</span> <span class="cm-variable">SND_ASYNC</span> <span class="cm-operator">|</span> <span class="cm-variable">SND_LOOP</span>);<span class="cm-comment">//开始播放</span></span></pre> | ||
637 | </div> | ||
638 | <div style="position: relative;"> | ||
639 | <div class="CodeMirror-gutter-wrapper" style="left: -28px;"> | ||
640 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
641 | style="left: 0px; width: 19px;">5</div> | ||
642 | </div> | ||
643 | <pre class=" CodeMirror-line " | ||
644 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">PlaySound</span>(<span class="cm-variable">NULL</span>,<span class="cm-variable">NULL</span>,<span class="cm-variable">SND_FILENAME</span>);<span class="cm-comment">//结束播放</span></span></pre> | ||
645 | </div> | ||
646 | </div> | ||
647 | </div> | ||
648 | </div> | ||
649 | </div> | ||
650 | </div> | ||
651 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 115px;"></div> | ||
652 | <div class="CodeMirror-gutters" style="height: 115px;"> | ||
653 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 27px;"></div> | ||
654 | </div> | ||
655 | </div> | ||
656 | </div> | ||
657 | </pre> | ||
658 | <p><span>注意:音频必须使用</span><strong><span>wav</span></strong><span>格式,必须放在</span><strong><span>跟代码同一个文件夹</span></strong><span>,如果不然,音乐名处</span><strong><span>应当使用其绝对地址或相对地址</span></strong><span>。</span> | ||
659 | </p> | ||
660 | <h1 id='震动心形设计'><span>震动心形设计</span></h1> | ||
661 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c" | ||
662 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
663 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
664 | <div>20</div> | ||
665 | </div> | ||
666 | </div> | ||
667 | <div class="CodeMirror-measure"></div> | ||
668 | <div style="position: relative; z-index: 1;"></div> | ||
669 | <div class="CodeMirror-code" role="presentation" style=""> | ||
670 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
671 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
672 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
673 | </div> | ||
674 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
675 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
676 | style="left: 0px; width: 27px;">1</div> | ||
677 | </div> | ||
678 | <pre class=" CodeMirror-line " | ||
679 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#define I 20</span></span></pre> | ||
680 | </div> | ||
681 | <div style="position: relative;"> | ||
682 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
683 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
684 | </div> | ||
685 | <pre class=" CodeMirror-line " | ||
686 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#define R 340</span></span></pre> | ||
687 | </div> | ||
688 | <div style="position: relative;"> | ||
689 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
690 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
691 | </div> | ||
692 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
693 | </span></span></pre> | ||
694 | </div> | ||
695 | <div style="position: relative;"> | ||
696 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
697 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
698 | </div> | ||
699 | <pre class=" CodeMirror-line " | ||
700 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-variable">wide</span><span class="cm-operator">=</span><span class="cm-number">80</span>,<span class="cm-variable">high</span><span class="cm-operator">=</span><span class="cm-number">40</span>;<span class="cm-comment">//宏常量定义,数据可变</span></span></pre> | ||
701 | </div> | ||
702 | <div style="position: relative;"> | ||
703 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
704 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
705 | </div> | ||
706 | <pre class=" CodeMirror-line " | ||
707 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">system</span>(<span class="cm-string">"title xxx"</span>);<span class="cm-comment">//运行框名称修改,主函数第一句</span></span></pre> | ||
708 | </div> | ||
709 | <div style="position: relative;"> | ||
710 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
711 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
712 | </div> | ||
713 | <pre class=" CodeMirror-line " | ||
714 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable">system</span>(<span class="cm-string">"mode con cols=80 lines=40 "</span>);<span class="cm-comment">//运行框大小限制</span></span></pre> | ||
715 | </div> | ||
716 | <div style="position: relative;"> | ||
717 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
718 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
719 | </div> | ||
720 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
721 | </span></span></pre> | ||
722 | </div> | ||
723 | <div style="position: relative;"> | ||
724 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
725 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
726 | </div> | ||
727 | <pre class=" CodeMirror-line " | ||
728 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">draw_color</span>()<span class="cm-comment">//整体颜色震动效果函数</span></span></pre> | ||
729 | </div> | ||
730 | <div style="position: relative;"> | ||
731 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
732 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
733 | </div> | ||
734 | <pre class=" CodeMirror-line " | ||
735 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
736 | </div> | ||
737 | <div style="position: relative;"> | ||
738 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
739 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
740 | style="left: 0px; width: 27px;">10</div> | ||
741 | </div> | ||
742 | <pre class=" CodeMirror-line " | ||
743 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">char</span> <span class="cm-variable">cl</span>[<span class="cm-number">20</span>]; </span></pre> | ||
744 | </div> | ||
745 | <div style="position: relative;"> | ||
746 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
747 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
748 | </div> | ||
749 | <pre class=" CodeMirror-line " | ||
750 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">srand</span>((<span class="cm-variable-3">unsigned</span> <span class="cm-variable-3">int</span>)<span class="cm-variable">time</span>(<span class="cm-variable">NULL</span>));</span></pre> | ||
751 | </div> | ||
752 | <div style="position: relative;"> | ||
753 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
754 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
755 | </div> | ||
756 | <pre class=" CodeMirror-line " | ||
757 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">k</span> <span class="cm-operator">=</span> <span class="cm-variable">rand</span>() <span class="cm-operator">%</span> <span class="cm-variable">strlen</span>(<span class="cm-variable">back_color</span>); </span></pre> | ||
758 | </div> | ||
759 | <div style="position: relative;"> | ||
760 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
761 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
762 | </div> | ||
763 | <pre class=" CodeMirror-line " | ||
764 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">strcpy</span>(<span class="cm-variable">cl</span>, <span class="cm-variable">Color</span>);</span></pre> | ||
765 | </div> | ||
766 | <div style="position: relative;"> | ||
767 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
768 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
769 | </div> | ||
770 | <pre class=" CodeMirror-line " | ||
771 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cl</span>[<span class="cm-variable">len</span>] <span class="cm-operator">=</span> <span class="cm-variable">back_color</span>[<span class="cm-variable">k</span>];</span></pre> | ||
772 | </div> | ||
773 | <div style="position: relative;"> | ||
774 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
775 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
776 | </div> | ||
777 | <pre class=" CodeMirror-line " | ||
778 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">srand</span>((<span class="cm-variable-3">unsigned</span> <span class="cm-variable-3">int</span>)<span class="cm-variable">time</span>(<span class="cm-variable">NULL</span>));</span></pre> | ||
779 | </div> | ||
780 | <div style="position: relative;"> | ||
781 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
782 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
783 | </div> | ||
784 | <pre class=" CodeMirror-line " | ||
785 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">k</span> <span class="cm-operator">=</span> <span class="cm-variable">rand</span>() <span class="cm-operator">%</span> <span class="cm-variable">strlen</span>(<span class="cm-variable">font_color</span>);</span></pre> | ||
786 | </div> | ||
787 | <div style="position: relative;"> | ||
788 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
789 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
790 | </div> | ||
791 | <pre class=" CodeMirror-line " | ||
792 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cl</span>[<span class="cm-variable">len</span> <span class="cm-operator">+</span> <span class="cm-number">1</span>] <span class="cm-operator">=</span> <span class="cm-variable">font_color</span>[<span class="cm-variable">k</span>];</span></pre> | ||
793 | </div> | ||
794 | <div style="position: relative;"> | ||
795 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
796 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | ||
797 | </div> | ||
798 | <pre class=" CodeMirror-line " | ||
799 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">cl</span>[<span class="cm-variable">len</span> <span class="cm-operator">+</span> <span class="cm-number">2</span>] <span class="cm-operator">=</span> <span class="cm-string">'\0'</span>;</span></pre> | ||
800 | </div> | ||
801 | <div style="position: relative;"> | ||
802 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
803 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
804 | </div> | ||
805 | <pre class=" CodeMirror-line " | ||
806 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">system</span>(<span class="cm-variable">cl</span>);</span></pre> | ||
807 | </div> | ||
808 | <div style="position: relative;"> | ||
809 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
810 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
811 | style="left: 0px; width: 27px;">20</div> | ||
812 | </div> | ||
813 | <pre class=" CodeMirror-line " | ||
814 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">} </span></pre> | ||
815 | </div> | ||
816 | </div> | ||
817 | </div> | ||
818 | </div> | ||
819 | </div> | ||
820 | </div> | ||
821 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 461px;"></div> | ||
822 | <div class="CodeMirror-gutters" style="height: 461px;"> | ||
823 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
824 | </div> | ||
825 | </div> | ||
826 | </div> | ||
827 | </pre> | ||
828 | <p><span>颜色震动使用方法实例:</span></p> | ||
829 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c" | ||
830 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
831 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
832 | <div>73</div> | ||
833 | </div> | ||
834 | </div> | ||
835 | <div class="CodeMirror-measure"></div> | ||
836 | <div style="position: relative; z-index: 1;"></div> | ||
837 | <div class="CodeMirror-code" role="presentation" style=""> | ||
838 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
839 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
840 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
841 | </div> | ||
842 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
843 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
844 | style="left: 0px; width: 27px;">1</div> | ||
845 | </div> | ||
846 | <pre class=" CodeMirror-line " | ||
847 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">0</span>;<span class="cm-variable">i</span><span class="cm-operator"><</span><span class="cm-number">6</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>,<span class="cm-variable">lower</span><span class="cm-operator">+=</span><span class="cm-number">3</span>)</span></pre> | ||
848 | </div> | ||
849 | <div style="position: relative;"> | ||
850 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
851 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
852 | </div> | ||
853 | <pre class=" CodeMirror-line " | ||
854 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
855 | </div> | ||
856 | <div style="position: relative;"> | ||
857 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
858 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
859 | </div> | ||
860 | <pre class=" CodeMirror-line " | ||
861 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">puts</span>(<span class="cm-variable">data</span>[<span class="cm-variable">i</span><span class="cm-operator">+</span><span class="cm-number">15</span>]);</span></pre> | ||
862 | </div> | ||
863 | <div style="position: relative;"> | ||
864 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
865 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
866 | </div> | ||
867 | <pre class=" CodeMirror-line " | ||
868 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">for</span>(<span class="cm-variable">j</span><span class="cm-operator">=</span><span class="cm-number">0</span>;<span class="cm-variable">j</span><span class="cm-operator"><</span><span class="cm-variable">wait</span>;<span class="cm-variable">j</span><span class="cm-operator">++</span>)</span></pre> | ||
869 | </div> | ||
870 | <div style="position: relative;"> | ||
871 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
872 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
873 | </div> | ||
874 | <pre class=" CodeMirror-line " | ||
875 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
876 | </div> | ||
877 | <div style="position: relative;"> | ||
878 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
879 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
880 | </div> | ||
881 | <pre class=" CodeMirror-line " | ||
882 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">draw_color</span>();</span></pre> | ||
883 | </div> | ||
884 | <div style="position: relative;"> | ||
885 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
886 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
887 | </div> | ||
888 | <pre class=" CodeMirror-line " | ||
889 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">Sleep</span>(<span class="cm-number">200</span>);</span></pre> | ||
890 | </div> | ||
891 | <div style="position: relative;"> | ||
892 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
893 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
894 | </div> | ||
895 | <pre class=" CodeMirror-line " | ||
896 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
897 | </div> | ||
898 | <div style="position: relative;"> | ||
899 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
900 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
901 | </div> | ||
902 | <pre class=" CodeMirror-line " | ||
903 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">Sleep</span>(<span class="cm-number">200</span>);</span></pre> | ||
904 | </div> | ||
905 | <div style="position: relative;"> | ||
906 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
907 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
908 | style="left: 0px; width: 27px;">10</div> | ||
909 | </div> | ||
910 | <pre class=" CodeMirror-line " | ||
911 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
912 | </div> | ||
913 | <div style="position: relative;"> | ||
914 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
915 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
916 | </div> | ||
917 | <pre class=" CodeMirror-line " | ||
918 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">void</span> <span class="cm-def">draw_heart</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">wait</span>)<span class="cm-comment">//心形设计函数,传入参数为0即可</span></span></pre> | ||
919 | </div> | ||
920 | <div style="position: relative;"> | ||
921 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
922 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
923 | </div> | ||
924 | <pre class=" CodeMirror-line " | ||
925 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
926 | </div> | ||
927 | <div style="position: relative;"> | ||
928 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
929 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
930 | </div> | ||
931 | <pre class=" CodeMirror-line " | ||
932 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable-3">int</span> <span class="cm-variable">i</span>,<span class="cm-variable">j</span>,<span class="cm-variable">e</span>,<span class="cm-variable">a</span>; </span></pre> | ||
933 | </div> | ||
934 | <div style="position: relative;"> | ||
935 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
936 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
937 | </div> | ||
938 | <pre class=" CodeMirror-line " | ||
939 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">1</span>,<span class="cm-variable">a</span><span class="cm-operator">=</span><span class="cm-variable">I</span>;<span class="cm-variable">i</span><span class="cm-operator"><</span><span class="cm-variable">I</span><span class="cm-operator">/</span><span class="cm-number">2</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>,<span class="cm-variable">a</span><span class="cm-operator">--</span>)</span></pre> | ||
940 | </div> | ||
941 | <div style="position: relative;"> | ||
942 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
943 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
944 | </div> | ||
945 | <pre class=" CodeMirror-line " | ||
946 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
947 | </div> | ||
948 | <div style="position: relative;"> | ||
949 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
950 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
951 | </div> | ||
952 | <pre class=" CodeMirror-line " | ||
953 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">j</span><span class="cm-operator">=</span>(<span class="cm-variable-3">int</span>) ( <span class="cm-variable">I</span><span class="cm-operator">-</span><span class="cm-variable">sqrt</span>(<span class="cm-variable">I</span><span class="cm-operator">*</span><span class="cm-variable">I</span><span class="cm-operator">-</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>)<span class="cm-operator">*</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>)) );<span class="cm-variable">j</span><span class="cm-operator">></span><span class="cm-number">0</span>;<span class="cm-variable">j</span><span class="cm-operator">--</span>)</span></pre> | ||
954 | </div> | ||
955 | <div style="position: relative;"> | ||
956 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
957 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
958 | </div> | ||
959 | <pre class=" CodeMirror-line " | ||
960 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
961 | </div> | ||
962 | <div style="position: relative;"> | ||
963 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
964 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | ||
965 | </div> | ||
966 | <pre class=" CodeMirror-line " | ||
967 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">" "</span>);</span></pre> | ||
968 | </div> | ||
969 | <div style="position: relative;"> | ||
970 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
971 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
972 | </div> | ||
973 | <pre class=" CodeMirror-line " | ||
974 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
975 | </div> | ||
976 | <div style="position: relative;"> | ||
977 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
978 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
979 | style="left: 0px; width: 27px;">20</div> | ||
980 | </div> | ||
981 | <pre class=" CodeMirror-line " | ||
982 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">e</span><span class="cm-operator">=</span><span class="cm-number">1</span>;<span class="cm-variable">e</span><span class="cm-operator"><=</span><span class="cm-number">2</span><span class="cm-operator">*</span><span class="cm-variable">sqrt</span>(<span class="cm-variable">I</span><span class="cm-operator">*</span><span class="cm-variable">I</span><span class="cm-operator">-</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>)<span class="cm-operator">*</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>));<span class="cm-variable">e</span><span class="cm-operator">++</span>)</span></pre> | ||
983 | </div> | ||
984 | <div style="position: relative;"> | ||
985 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
986 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div> | ||
987 | </div> | ||
988 | <pre class=" CodeMirror-line " | ||
989 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
990 | </div> | ||
991 | <div style="position: relative;"> | ||
992 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
993 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div> | ||
994 | </div> | ||
995 | <pre class=" CodeMirror-line " | ||
996 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"\3"</span>);</span></pre> | ||
997 | </div> | ||
998 | <div style="position: relative;"> | ||
999 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1000 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div> | ||
1001 | </div> | ||
1002 | <pre class=" CodeMirror-line " | ||
1003 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
1004 | </div> | ||
1005 | <div style="position: relative;"> | ||
1006 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1007 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div> | ||
1008 | </div> | ||
1009 | <pre class=" CodeMirror-line " | ||
1010 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">j</span><span class="cm-operator">=</span>(<span class="cm-variable-3">int</span>)( <span class="cm-number">2</span><span class="cm-operator">*</span>( <span class="cm-variable">I</span><span class="cm-operator">-</span><span class="cm-variable">sqrt</span>(<span class="cm-variable">I</span><span class="cm-operator">*</span><span class="cm-variable">I</span><span class="cm-operator">-</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>)<span class="cm-operator">*</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>)) ) );<span class="cm-variable">j</span><span class="cm-operator">></span><span class="cm-number">0</span>;<span class="cm-variable">j</span><span class="cm-operator">--</span>)</span></pre> | ||
1011 | </div> | ||
1012 | <div style="position: relative;"> | ||
1013 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1014 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div> | ||
1015 | </div> | ||
1016 | <pre class=" CodeMirror-line " | ||
1017 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1018 | </div> | ||
1019 | <div style="position: relative;"> | ||
1020 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1021 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div> | ||
1022 | </div> | ||
1023 | <pre class=" CodeMirror-line " | ||
1024 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">" "</span>);</span></pre> | ||
1025 | </div> | ||
1026 | <div style="position: relative;"> | ||
1027 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1028 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div> | ||
1029 | </div> | ||
1030 | <pre class=" CodeMirror-line " | ||
1031 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
1032 | </div> | ||
1033 | <div style="position: relative;"> | ||
1034 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1035 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div> | ||
1036 | </div> | ||
1037 | <pre class=" CodeMirror-line " | ||
1038 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">e</span><span class="cm-operator">=</span><span class="cm-number">1</span>;<span class="cm-variable">e</span><span class="cm-operator"><=</span><span class="cm-number">2</span><span class="cm-operator">*</span><span class="cm-variable">sqrt</span>(<span class="cm-variable">I</span><span class="cm-operator">*</span><span class="cm-variable">I</span><span class="cm-operator">-</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>)<span class="cm-operator">*</span>(<span class="cm-variable">a</span><span class="cm-operator">-</span><span class="cm-variable">i</span>));<span class="cm-variable">e</span><span class="cm-operator">++</span>)</span></pre> | ||
1039 | </div> | ||
1040 | <div style="position: relative;"> | ||
1041 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1042 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div> | ||
1043 | </div> | ||
1044 | <pre class=" CodeMirror-line " | ||
1045 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1046 | </div> | ||
1047 | <div style="position: relative;"> | ||
1048 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1049 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1050 | style="left: 0px; width: 27px;">30</div> | ||
1051 | </div> | ||
1052 | <pre class=" CodeMirror-line " | ||
1053 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"\3"</span>);</span></pre> | ||
1054 | </div> | ||
1055 | <div style="position: relative;"> | ||
1056 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1057 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div> | ||
1058 | </div> | ||
1059 | <pre class=" CodeMirror-line " | ||
1060 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
1061 | </div> | ||
1062 | <div style="position: relative;"> | ||
1063 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1064 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div> | ||
1065 | </div> | ||
1066 | <pre class=" CodeMirror-line " | ||
1067 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">printf</span>(<span class="cm-string">"\n"</span>);</span></pre> | ||
1068 | </div> | ||
1069 | <div style="position: relative;"> | ||
1070 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1071 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div> | ||
1072 | </div> | ||
1073 | <pre class=" CodeMirror-line " | ||
1074 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">wait</span><span class="cm-operator">&&</span><span class="cm-variable">i</span><span class="cm-operator">%</span><span class="cm-number">2</span>)</span></pre> | ||
1075 | </div> | ||
1076 | <div style="position: relative;"> | ||
1077 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1078 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">34</div> | ||
1079 | </div> | ||
1080 | <pre class=" CodeMirror-line " | ||
1081 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1082 | </div> | ||
1083 | <div style="position: relative;"> | ||
1084 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1085 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">35</div> | ||
1086 | </div> | ||
1087 | <pre class=" CodeMirror-line " | ||
1088 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">draw_color</span>();</span></pre> | ||
1089 | </div> | ||
1090 | <div style="position: relative;"> | ||
1091 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1092 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">36</div> | ||
1093 | </div> | ||
1094 | <pre class=" CodeMirror-line " | ||
1095 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">Sleep</span>(<span class="cm-number">80</span>); </span></pre> | ||
1096 | </div> | ||
1097 | <div style="position: relative;"> | ||
1098 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1099 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">37</div> | ||
1100 | </div> | ||
1101 | <pre class=" CodeMirror-line " | ||
1102 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
1103 | </div> | ||
1104 | <div style="position: relative;"> | ||
1105 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1106 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">38</div> | ||
1107 | </div> | ||
1108 | <pre class=" CodeMirror-line " | ||
1109 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
1110 | </div> | ||
1111 | <div style="position: relative;"> | ||
1112 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1113 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">39</div> | ||
1114 | </div> | ||
1115 | <pre class=" CodeMirror-line " | ||
1116 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">1</span>;<span class="cm-variable">i</span><span class="cm-operator"><</span><span class="cm-number">80</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre> | ||
1117 | </div> | ||
1118 | <div style="position: relative;"> | ||
1119 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1120 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1121 | style="left: 0px; width: 27px;">40</div> | ||
1122 | </div> | ||
1123 | <pre class=" CodeMirror-line " | ||
1124 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1125 | </div> | ||
1126 | <div style="position: relative;"> | ||
1127 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1128 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">41</div> | ||
1129 | </div> | ||
1130 | <pre class=" CodeMirror-line " | ||
1131 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">i</span><span class="cm-operator">==</span><span class="cm-number">20</span>)</span></pre> | ||
1132 | </div> | ||
1133 | <div style="position: relative;"> | ||
1134 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1135 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">42</div> | ||
1136 | </div> | ||
1137 | <pre class=" CodeMirror-line " | ||
1138 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1139 | </div> | ||
1140 | <div style="position: relative;"> | ||
1141 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1142 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">43</div> | ||
1143 | </div> | ||
1144 | <pre class=" CodeMirror-line " | ||
1145 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable-3">int</span> <span class="cm-variable">j</span><span class="cm-operator">=</span><span class="cm-number">0</span>;<span class="cm-variable">j</span><span class="cm-operator"><</span><span class="cm-number">40</span>;<span class="cm-variable">j</span><span class="cm-operator">++</span>)</span></pre> | ||
1146 | </div> | ||
1147 | <div style="position: relative;"> | ||
1148 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1149 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">44</div> | ||
1150 | </div> | ||
1151 | <pre class=" CodeMirror-line " | ||
1152 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> {</span></pre> | ||
1153 | </div> | ||
1154 | <div style="position: relative;"> | ||
1155 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1156 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">45</div> | ||
1157 | </div> | ||
1158 | <pre class=" CodeMirror-line " | ||
1159 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">printf</span>(<span class="cm-string">"\3"</span>);</span></pre> | ||
1160 | </div> | ||
1161 | <div style="position: relative;"> | ||
1162 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1163 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">46</div> | ||
1164 | </div> | ||
1165 | <pre class=" CodeMirror-line " | ||
1166 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
1167 | </div> | ||
1168 | <div style="position: relative;"> | ||
1169 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1170 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">47</div> | ||
1171 | </div> | ||
1172 | <pre class=" CodeMirror-line " | ||
1173 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">i</span><span class="cm-operator">+=</span><span class="cm-number">40</span>;</span></pre> | ||
1174 | </div> | ||
1175 | <div style="position: relative;"> | ||
1176 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1177 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">48</div> | ||
1178 | </div> | ||
1179 | <pre class=" CodeMirror-line " | ||
1180 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
1181 | </div> | ||
1182 | <div style="position: relative;"> | ||
1183 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1184 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">49</div> | ||
1185 | </div> | ||
1186 | <pre class=" CodeMirror-line " | ||
1187 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">printf</span>(<span class="cm-string">"\3"</span>);</span></pre> | ||
1188 | </div> | ||
1189 | <div style="position: relative;"> | ||
1190 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1191 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1192 | style="left: 0px; width: 27px;">50</div> | ||
1193 | </div> | ||
1194 | <pre class=" CodeMirror-line " | ||
1195 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
1196 | </div> | ||
1197 | <div style="position: relative;"> | ||
1198 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1199 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">51</div> | ||
1200 | </div> | ||
1201 | <pre class=" CodeMirror-line " | ||
1202 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">printf</span>(<span class="cm-string">"\n"</span>);</span></pre> | ||
1203 | </div> | ||
1204 | <div style="position: relative;"> | ||
1205 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1206 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">52</div> | ||
1207 | </div> | ||
1208 | <pre class=" CodeMirror-line " | ||
1209 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">i</span><span class="cm-operator">=</span><span class="cm-number">1</span>;<span class="cm-variable">i</span><span class="cm-operator"><=</span><span class="cm-variable">R</span><span class="cm-operator">/</span><span class="cm-number">2</span>;<span class="cm-variable">i</span><span class="cm-operator">++</span>)</span></pre> | ||
1210 | </div> | ||
1211 | <div style="position: relative;"> | ||
1212 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1213 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">53</div> | ||
1214 | </div> | ||
1215 | <pre class=" CodeMirror-line " | ||
1216 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1217 | </div> | ||
1218 | <div style="position: relative;"> | ||
1219 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1220 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">54</div> | ||
1221 | </div> | ||
1222 | <pre class=" CodeMirror-line " | ||
1223 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">i</span><span class="cm-operator">%</span><span class="cm-number">2</span><span class="cm-operator">||</span><span class="cm-variable">i</span><span class="cm-operator">%</span><span class="cm-number">3</span>)</span></pre> | ||
1224 | </div> | ||
1225 | <div style="position: relative;"> | ||
1226 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1227 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">55</div> | ||
1228 | </div> | ||
1229 | <pre class=" CodeMirror-line " | ||
1230 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1231 | </div> | ||
1232 | <div style="position: relative;"> | ||
1233 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1234 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">56</div> | ||
1235 | </div> | ||
1236 | <pre class=" CodeMirror-line " | ||
1237 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">continue</span>;</span></pre> | ||
1238 | </div> | ||
1239 | <div style="position: relative;"> | ||
1240 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1241 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">57</div> | ||
1242 | </div> | ||
1243 | <pre class=" CodeMirror-line " | ||
1244 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
1245 | </div> | ||
1246 | <div style="position: relative;"> | ||
1247 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1248 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">58</div> | ||
1249 | </div> | ||
1250 | <pre class=" CodeMirror-line " | ||
1251 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">j</span><span class="cm-operator">=</span>(<span class="cm-variable-3">int</span>) ( <span class="cm-variable">R</span><span class="cm-operator">-</span><span class="cm-variable">sqrt</span>(<span class="cm-variable">R</span><span class="cm-operator">*</span><span class="cm-variable">R</span><span class="cm-operator">-</span><span class="cm-variable">i</span><span class="cm-operator">*</span><span class="cm-variable">i</span>) );<span class="cm-variable">j</span><span class="cm-operator">></span><span class="cm-number">0</span>;<span class="cm-variable">j</span><span class="cm-operator">--</span>)</span></pre> | ||
1252 | </div> | ||
1253 | <div style="position: relative;"> | ||
1254 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1255 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">59</div> | ||
1256 | </div> | ||
1257 | <pre class=" CodeMirror-line " | ||
1258 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1259 | </div> | ||
1260 | <div style="position: relative;"> | ||
1261 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1262 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1263 | style="left: 0px; width: 27px;">60</div> | ||
1264 | </div> | ||
1265 | <pre class=" CodeMirror-line " | ||
1266 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">" "</span>);</span></pre> | ||
1267 | </div> | ||
1268 | <div style="position: relative;"> | ||
1269 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1270 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">61</div> | ||
1271 | </div> | ||
1272 | <pre class=" CodeMirror-line " | ||
1273 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
1274 | </div> | ||
1275 | <div style="position: relative;"> | ||
1276 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1277 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">62</div> | ||
1278 | </div> | ||
1279 | <pre class=" CodeMirror-line " | ||
1280 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">for</span>(<span class="cm-variable">e</span><span class="cm-operator">=</span><span class="cm-number">1</span>;<span class="cm-variable">e</span><span class="cm-operator"><=</span><span class="cm-number">2</span><span class="cm-operator">*</span>( <span class="cm-variable">sqrt</span>(<span class="cm-variable">R</span><span class="cm-operator">*</span><span class="cm-variable">R</span><span class="cm-operator">-</span><span class="cm-variable">i</span><span class="cm-operator">*</span><span class="cm-variable">i</span>) <span class="cm-operator">-</span> (<span class="cm-variable">R</span><span class="cm-operator">-</span><span class="cm-number">2</span><span class="cm-operator">*</span><span class="cm-variable">I</span>) );<span class="cm-variable">e</span><span class="cm-operator">++</span>)</span></pre> | ||
1281 | </div> | ||
1282 | <div style="position: relative;"> | ||
1283 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1284 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">63</div> | ||
1285 | </div> | ||
1286 | <pre class=" CodeMirror-line " | ||
1287 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1288 | </div> | ||
1289 | <div style="position: relative;"> | ||
1290 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1291 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">64</div> | ||
1292 | </div> | ||
1293 | <pre class=" CodeMirror-line " | ||
1294 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">printf</span>(<span class="cm-string">"\3"</span>);</span></pre> | ||
1295 | </div> | ||
1296 | <div style="position: relative;"> | ||
1297 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1298 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">65</div> | ||
1299 | </div> | ||
1300 | <pre class=" CodeMirror-line " | ||
1301 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
1302 | </div> | ||
1303 | <div style="position: relative;"> | ||
1304 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1305 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">66</div> | ||
1306 | </div> | ||
1307 | <pre class=" CodeMirror-line " | ||
1308 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">printf</span>(<span class="cm-string">"\n"</span>);</span></pre> | ||
1309 | </div> | ||
1310 | <div style="position: relative;"> | ||
1311 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1312 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">67</div> | ||
1313 | </div> | ||
1314 | <pre class=" CodeMirror-line " | ||
1315 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-keyword">if</span>(<span class="cm-variable">wait</span>)</span></pre> | ||
1316 | </div> | ||
1317 | <div style="position: relative;"> | ||
1318 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1319 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">68</div> | ||
1320 | </div> | ||
1321 | <pre class=" CodeMirror-line " | ||
1322 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span>{</span></pre> | ||
1323 | </div> | ||
1324 | <div style="position: relative;"> | ||
1325 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1326 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">69</div> | ||
1327 | </div> | ||
1328 | <pre class=" CodeMirror-line " | ||
1329 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">draw_color</span>();</span></pre> | ||
1330 | </div> | ||
1331 | <div style="position: relative;"> | ||
1332 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1333 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1334 | style="left: 0px; width: 27px;">70</div> | ||
1335 | </div> | ||
1336 | <pre class=" CodeMirror-line " | ||
1337 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-variable">Sleep</span>(<span class="cm-number">80</span>); </span></pre> | ||
1338 | </div> | ||
1339 | <div style="position: relative;"> | ||
1340 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1341 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">71</div> | ||
1342 | </div> | ||
1343 | <pre class=" CodeMirror-line " | ||
1344 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
1345 | </div> | ||
1346 | <div style="position: relative;"> | ||
1347 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1348 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">72</div> | ||
1349 | </div> | ||
1350 | <pre class=" CodeMirror-line " | ||
1351 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> }</span></pre> | ||
1352 | </div> | ||
1353 | <div style="position: relative;"> | ||
1354 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1355 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1356 | style="left: 0px; width: 27px;">73</div> | ||
1357 | </div> | ||
1358 | <pre class=" CodeMirror-line " | ||
1359 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
1360 | </div> | ||
1361 | </div> | ||
1362 | </div> | ||
1363 | </div> | ||
1364 | </div> | ||
1365 | </div> | ||
1366 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 1682px;"></div> | ||
1367 | <div class="CodeMirror-gutters" style="height: 1682px;"> | ||
1368 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
1369 | </div> | ||
1370 | </div> | ||
1371 | </div> | ||
1372 | </pre> | ||
1373 | <h1 id='给代码加行号的代码'><span>给代码加行号的代码</span></h1> | ||
1374 | <pre class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" spellcheck="false" lang="c" | ||
1375 | style="break-inside: unset;"><div class="CodeMirror cm-s-inner cm-s-null-scroll CodeMirror-wrap" lang="c"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 9.51875px; left: 44px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 36px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre> | ||
1376 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt"> | ||
1377 | <div>34</div> | ||
1378 | </div> | ||
1379 | </div> | ||
1380 | <div class="CodeMirror-measure"></div> | ||
1381 | <div style="position: relative; z-index: 1;"></div> | ||
1382 | <div class="CodeMirror-code" role="presentation" style=""> | ||
1383 | <div class="CodeMirror-activeline" style="position: relative;"> | ||
1384 | <div class="CodeMirror-activeline-background CodeMirror-linebackground"></div> | ||
1385 | <div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: -36px; width: 36px;"> | ||
1386 | </div> | ||
1387 | <div class="CodeMirror-gutter-wrapper CodeMirror-activeline-gutter" style="left: -36px;"> | ||
1388 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1389 | style="left: 0px; width: 27px;">1</div> | ||
1390 | </div> | ||
1391 | <pre class=" CodeMirror-line " | ||
1392 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-meta">#include<stdio.h></span></span></pre> | ||
1393 | </div> | ||
1394 | <div style="position: relative;"> | ||
1395 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1396 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">2</div> | ||
1397 | </div> | ||
1398 | <pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="" cm-zwsp=""> | ||
1399 | </span></span></pre> | ||
1400 | </div> | ||
1401 | <div style="position: relative;"> | ||
1402 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1403 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">3</div> | ||
1404 | </div> | ||
1405 | <pre class=" CodeMirror-line " | ||
1406 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-variable-3">int</span> <span class="cm-def">main</span>(<span class="cm-variable-3">void</span>)</span></pre> | ||
1407 | </div> | ||
1408 | <div style="position: relative;"> | ||
1409 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1410 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">4</div> | ||
1411 | </div> | ||
1412 | <pre class=" CodeMirror-line " | ||
1413 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">{</span></pre> | ||
1414 | </div> | ||
1415 | <div style="position: relative;"> | ||
1416 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1417 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">5</div> | ||
1418 | </div> | ||
1419 | <pre class=" CodeMirror-line " | ||
1420 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">FILE</span> <span class="cm-operator">*</span><span class="cm-variable">fpIn</span>;</span></pre> | ||
1421 | </div> | ||
1422 | <div style="position: relative;"> | ||
1423 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1424 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">6</div> | ||
1425 | </div> | ||
1426 | <pre class=" CodeMirror-line " | ||
1427 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"> <span class="cm-comment">// 输入文件的指针</span></span></pre> | ||
1428 | </div> | ||
1429 | <div style="position: relative;"> | ||
1430 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1431 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">7</div> | ||
1432 | </div> | ||
1433 | <pre class=" CodeMirror-line " | ||
1434 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">FILE</span> <span class="cm-operator">*</span><span class="cm-variable">fpOut</span>;</span></pre> | ||
1435 | </div> | ||
1436 | <div style="position: relative;"> | ||
1437 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1438 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">8</div> | ||
1439 | </div> | ||
1440 | <pre class=" CodeMirror-line " | ||
1441 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">// 输出文件的指针</span></span></pre> | ||
1442 | </div> | ||
1443 | <div style="position: relative;"> | ||
1444 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1445 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">9</div> | ||
1446 | </div> | ||
1447 | <pre class=" CodeMirror-line " | ||
1448 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">char</span> <span class="cm-variable">str</span>[<span class="cm-number">1000</span>];</span></pre> | ||
1449 | </div> | ||
1450 | <div style="position: relative;"> | ||
1451 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1452 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1453 | style="left: 0px; width: 27px;">10</div> | ||
1454 | </div> | ||
1455 | <pre class=" CodeMirror-line " | ||
1456 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">// 用来存储从文件中读取出的”一行“字符串信息</span></span></pre> | ||
1457 | </div> | ||
1458 | <div style="position: relative;"> | ||
1459 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1460 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">11</div> | ||
1461 | </div> | ||
1462 | <pre class=" CodeMirror-line " | ||
1463 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable-3">int</span> <span class="cm-variable">row</span> <span class="cm-operator">=</span> <span class="cm-number">1</span>;</span></pre> | ||
1464 | </div> | ||
1465 | <div style="position: relative;"> | ||
1466 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1467 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">12</div> | ||
1468 | </div> | ||
1469 | <pre class=" CodeMirror-line " | ||
1470 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fpIn</span> <span class="cm-operator">=</span> <span class="cm-variable">fopen</span>(<span class="cm-string">"文件名.cpp"</span>, <span class="cm-string">"r"</span>);</span></pre> | ||
1471 | </div> | ||
1472 | <div style="position: relative;"> | ||
1473 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1474 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">13</div> | ||
1475 | </div> | ||
1476 | <pre class=" CodeMirror-line " | ||
1477 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">/* 以只读和文本格式打开需要的.cpp文件</span></span></pre> | ||
1478 | </div> | ||
1479 | <div style="position: relative;"> | ||
1480 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1481 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">14</div> | ||
1482 | </div> | ||
1483 | <pre class=" CodeMirror-line " | ||
1484 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-comment">*这里的文件名无所谓大小写</span></span></pre> | ||
1485 | </div> | ||
1486 | <div style="position: relative;"> | ||
1487 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1488 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">15</div> | ||
1489 | </div> | ||
1490 | <pre class=" CodeMirror-line " | ||
1491 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-comment">*/</span></span></pre> | ||
1492 | </div> | ||
1493 | <div style="position: relative;"> | ||
1494 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1495 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">16</div> | ||
1496 | </div> | ||
1497 | <pre class=" CodeMirror-line " | ||
1498 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fpOut</span> <span class="cm-operator">=</span> <span class="cm-variable">fopen</span>(<span class="cm-string">"文件名.txt"</span>, <span class="cm-string">"w"</span>);</span></pre> | ||
1499 | </div> | ||
1500 | <div style="position: relative;"> | ||
1501 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1502 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">17</div> | ||
1503 | </div> | ||
1504 | <pre class=" CodeMirror-line " | ||
1505 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">// 以创建方式(也叫写方式)打开文件名.txt文件</span></span></pre> | ||
1506 | </div> | ||
1507 | <div style="position: relative;"> | ||
1508 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1509 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">18</div> | ||
1510 | </div> | ||
1511 | <pre class=" CodeMirror-line " | ||
1512 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fgets</span>(<span class="cm-variable">str</span>, <span class="cm-number">81</span>, <span class="cm-variable">fpIn</span>);</span></pre> | ||
1513 | </div> | ||
1514 | <div style="position: relative;"> | ||
1515 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1516 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">19</div> | ||
1517 | </div> | ||
1518 | <pre class=" CodeMirror-line " | ||
1519 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">/* 从文件中读取一行信息,保存到str数组中。</span></span></pre> | ||
1520 | </div> | ||
1521 | <div style="position: relative;"> | ||
1522 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1523 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1524 | style="left: 0px; width: 27px;">20</div> | ||
1525 | </div> | ||
1526 | <pre class=" CodeMirror-line " | ||
1527 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-comment">*这里要注意的是这个81,</span></span></pre> | ||
1528 | </div> | ||
1529 | <div style="position: relative;"> | ||
1530 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1531 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">21</div> | ||
1532 | </div> | ||
1533 | <pre class=" CodeMirror-line " | ||
1534 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-comment">*一般情况下,编写文本格式文件的人,都习惯遇到行尾就敲回车,</span></span></pre> | ||
1535 | </div> | ||
1536 | <div style="position: relative;"> | ||
1537 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1538 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">22</div> | ||
1539 | </div> | ||
1540 | <pre class=" CodeMirror-line " | ||
1541 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-comment">*所以,一般情况下,文本文件一行最多80个字符。</span></span></pre> | ||
1542 | </div> | ||
1543 | <div style="position: relative;"> | ||
1544 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1545 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">23</div> | ||
1546 | </div> | ||
1547 | <pre class=" CodeMirror-line " | ||
1548 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-comment">*如果,一行不够80个字符,这个函数会自动只读到'\n'就结束了。</span></span></pre> | ||
1549 | </div> | ||
1550 | <div style="position: relative;"> | ||
1551 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1552 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">24</div> | ||
1553 | </div> | ||
1554 | <pre class=" CodeMirror-line " | ||
1555 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span> <span class="cm-comment">*/</span></span></pre> | ||
1556 | </div> | ||
1557 | <div style="position: relative;"> | ||
1558 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1559 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">25</div> | ||
1560 | </div> | ||
1561 | <pre class=" CodeMirror-line " | ||
1562 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-keyword">while</span>(<span class="cm-operator">!</span><span class="cm-variable">feof</span>(<span class="cm-variable">fpIn</span>))</span></pre> | ||
1563 | </div> | ||
1564 | <div style="position: relative;"> | ||
1565 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1566 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">26</div> | ||
1567 | </div> | ||
1568 | <pre class=" CodeMirror-line " | ||
1569 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>{ <span class="cm-comment">// 判断上一次fgets()是否正常(即,没有遇到文件尾部)</span></span></pre> | ||
1570 | </div> | ||
1571 | <div style="position: relative;"> | ||
1572 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1573 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">27</div> | ||
1574 | </div> | ||
1575 | <pre class=" CodeMirror-line " | ||
1576 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fprintf</span>(<span class="cm-variable">fpOut</span>, <span class="cm-string">"%4d %s"</span>, <span class="cm-variable">row</span>, <span class="cm-variable">str</span>);</span></pre> | ||
1577 | </div> | ||
1578 | <div style="position: relative;"> | ||
1579 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1580 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">28</div> | ||
1581 | </div> | ||
1582 | <pre class=" CodeMirror-line " | ||
1583 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-comment">// 在读入的每一行信息前,加入0000到9999的行号(应该够用了吧),呵呵呵呵</span></span></pre> | ||
1584 | </div> | ||
1585 | <div style="position: relative;"> | ||
1586 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1587 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">29</div> | ||
1588 | </div> | ||
1589 | <pre class=" CodeMirror-line " | ||
1590 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">row</span><span class="cm-operator">++</span>; <span class="cm-comment">// 行号加一</span></span></pre> | ||
1591 | </div> | ||
1592 | <div style="position: relative;"> | ||
1593 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1594 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1595 | style="left: 0px; width: 27px;">30</div> | ||
1596 | </div> | ||
1597 | <pre class=" CodeMirror-line " | ||
1598 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fgets</span>(<span class="cm-variable">str</span>, <span class="cm-number">81</span>, <span class="cm-variable">fpIn</span>); <span class="cm-comment">// 读取下一行</span></span></pre> | ||
1599 | </div> | ||
1600 | <div style="position: relative;"> | ||
1601 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1602 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">31</div> | ||
1603 | </div> | ||
1604 | <pre class=" CodeMirror-line " | ||
1605 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span>}</span></pre> | ||
1606 | </div> | ||
1607 | <div style="position: relative;"> | ||
1608 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1609 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">32</div> | ||
1610 | </div> | ||
1611 | <pre class=" CodeMirror-line " | ||
1612 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fclose</span>(<span class="cm-variable">fpIn</span>); <span class="cm-comment">// 关闭文件</span></span></pre> | ||
1613 | </div> | ||
1614 | <div style="position: relative;"> | ||
1615 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1616 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt" style="left: 0px; width: 27px;">33</div> | ||
1617 | </div> | ||
1618 | <pre class=" CodeMirror-line " | ||
1619 | role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span class="cm-tab" role="presentation" cm-text=" "> </span><span class="cm-variable">fclose</span>(<span class="cm-variable">fpOut</span>);</span></pre> | ||
1620 | </div> | ||
1621 | <div style="position: relative;"> | ||
1622 | <div class="CodeMirror-gutter-wrapper" style="left: -36px;"> | ||
1623 | <div class="CodeMirror-linenumber CodeMirror-gutter-elt CodeMirror-linenumber-show" | ||
1624 | style="left: 0px; width: 27px;">34</div> | ||
1625 | </div> | ||
1626 | <pre class=" CodeMirror-line " | ||
1627 | role="presentation"><span role="presentation" style="padding-right: 0.1px;">}</span></pre> | ||
1628 | </div> | 232 | </div> |
1629 | </div> | 233 | </div> |
1630 | </div> | ||
1631 | </div> | ||
1632 | </div> | ||
1633 | </div> | ||
1634 | <div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 783px;"></div> | ||
1635 | <div class="CodeMirror-gutters" style="height: 783px;"> | ||
1636 | <div class="CodeMirror-gutter CodeMirror-linenumbers" style="width: 35px;"></div> | ||
1637 | </div> | ||
1638 | </div> | ||
1639 | </div> | ||
1640 | </pre> | ||
1641 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | ||
1642 | </div> | ||
1643 | </div> | ||
1644 | </body> | 234 | </body> |
1645 | 235 | ||
1646 | </html> \ No newline at end of file | 236 | </html> \ No newline at end of file |
diff --git a/code/linux/aliyun_cloud.html b/code/linux/aliyun_cloud.html index dd1e429..bab99aa 100644 --- a/code/linux/aliyun_cloud.html +++ b/code/linux/aliyun_cloud.html | |||
@@ -7,6 +7,7 @@ | |||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
8 | <title>我的免费云服</title> | 8 | <title>我的免费云服</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
11 | </head> | 12 | </head> |
12 | 13 | ||
diff --git a/code/linux/gitserver.html b/code/linux/gitserver.html index 359d948..ac3f07a 100644 --- a/code/linux/gitserver.html +++ b/code/linux/gitserver.html | |||
@@ -7,6 +7,7 @@ | |||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
8 | <title>自己的git托管</title> | 8 | <title>自己的git托管</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
11 | </head> | 12 | </head> |
12 | 13 | ||
diff --git a/code/linux/httpmyserver.html b/code/linux/httpmyserver.html index 9cb878e..b4f1337 100644 --- a/code/linux/httpmyserver.html +++ b/code/linux/httpmyserver.html | |||
@@ -7,6 +7,7 @@ | |||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
8 | <title>http浏览服务器文件</title> | 8 | <title>http浏览服务器文件</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
11 | </head> | 12 | </head> |
12 | 13 | ||
@@ -268,7 +269,7 @@ def do_POST(self): | |||
268 | </p> | 269 | </p> |
269 | <p>这个服务默认运行在 8000 端口,你可以按照文件最后的<code>main</code>函数里的参数来修改运行端口。到了这一步,你也可以像为其他网络服务配置 https 一样,使用你的网络服务软件(如 | 270 | <p>这个服务默认运行在 8000 端口,你可以按照文件最后的<code>main</code>函数里的参数来修改运行端口。到了这一步,你也可以像为其他网络服务配置 https 一样,使用你的网络服务软件(如 |
270 | nginx、apache 之类)为之配置域名和 https 服务了,多好~</p> | 271 | nginx、apache 之类)为之配置域名和 https 服务了,多好~</p> |
271 | <p class="time">2023.1.3晚</p> | 272 | <p class="time">2024.1.3晚</p> |
272 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | 273 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> |
273 | </div> | 274 | </div> |
274 | </div> | 275 | </div> |
diff --git a/code/linux/keymap.html b/code/linux/keymap.html index 101244d..97f64d6 100644 --- a/code/linux/keymap.html +++ b/code/linux/keymap.html | |||
@@ -6,6 +6,7 @@ | |||
6 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
7 | <title>键盘映射</title> | 7 | <title>键盘映射</title> |
8 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 8 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
9 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
9 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
10 | </head> | 11 | </head> |
11 | 12 | ||
diff --git a/code/linux/vim.html b/code/linux/vim.html index fc1f145..badf5d5 100644 --- a/code/linux/vim.html +++ b/code/linux/vim.html | |||
@@ -7,6 +7,7 @@ | |||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
8 | <title>vim学习与我的配置</title> | 8 | <title>vim学习与我的配置</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
11 | </head> | 12 | </head> |
12 | 13 | ||
@@ -51,13 +52,355 @@ | |||
51 | </tbody> | 52 | </tbody> |
52 | </table> | 53 | </table> |
53 | <p>其关系如下:</p> | 54 | <p>其关系如下:</p> |
54 | <pre><code>graph LR | 55 | <div class="md-diagram-panel md-fences-adv-panel" lang="mermaid"><svg id="mermaidChart0" width="100%" |
55 | N(Normal)--->I(Insert) | 56 | xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" |
56 | N--->V(Visual) | 57 | style="max-width: 262.825px; margin: auto;" viewBox="-8 -8 262.82501220703125 235.02500915527344" |
57 | N--->R(Replace) | 58 | role="graphics-document document" aria-roledescription="flowchart-v2"> |
58 | I-->N | 59 | <style> |
59 | V-->N | 60 | #mermaidChart0 { |
60 | R-->N</code></pre> | 61 | font-family: sans-serif; |
62 | font-size: 16px; | ||
63 | fill: #333; | ||
64 | } | ||
65 | |||
66 | #mermaidChart0 .error-icon { | ||
67 | fill: #552222; | ||
68 | } | ||
69 | |||
70 | #mermaidChart0 .error-text { | ||
71 | fill: #552222; | ||
72 | stroke: #552222; | ||
73 | } | ||
74 | |||
75 | #mermaidChart0 .edge-thickness-normal { | ||
76 | stroke-width: 2px; | ||
77 | } | ||
78 | |||
79 | #mermaidChart0 .edge-thickness-thick { | ||
80 | stroke-width: 3.5px; | ||
81 | } | ||
82 | |||
83 | #mermaidChart0 .edge-pattern-solid { | ||
84 | stroke-dasharray: 0; | ||
85 | } | ||
86 | |||
87 | #mermaidChart0 .edge-pattern-dashed { | ||
88 | stroke-dasharray: 3; | ||
89 | } | ||
90 | |||
91 | #mermaidChart0 .edge-pattern-dotted { | ||
92 | stroke-dasharray: 2; | ||
93 | } | ||
94 | |||
95 | #mermaidChart0 .marker { | ||
96 | fill: #333333; | ||
97 | stroke: #333333; | ||
98 | } | ||
99 | |||
100 | #mermaidChart0 .marker.cross { | ||
101 | stroke: #333333; | ||
102 | } | ||
103 | |||
104 | #mermaidChart0 svg { | ||
105 | font-family: sans-serif; | ||
106 | font-size: 16px; | ||
107 | } | ||
108 | |||
109 | #mermaidChart0 .label { | ||
110 | font-family: sans-serif; | ||
111 | color: #333; | ||
112 | } | ||
113 | |||
114 | #mermaidChart0 .cluster-label text { | ||
115 | fill: #333; | ||
116 | } | ||
117 | |||
118 | #mermaidChart0 .cluster-label span, | ||
119 | #mermaidChart0 p { | ||
120 | color: #333; | ||
121 | } | ||
122 | |||
123 | #mermaidChart0 .label text, | ||
124 | #mermaidChart0 span, | ||
125 | #mermaidChart0 p { | ||
126 | fill: #333; | ||
127 | color: #333; | ||
128 | } | ||
129 | |||
130 | #mermaidChart0 .node rect, | ||
131 | #mermaidChart0 .node circle, | ||
132 | #mermaidChart0 .node ellipse, | ||
133 | #mermaidChart0 .node polygon, | ||
134 | #mermaidChart0 .node path { | ||
135 | fill: #ECECFF; | ||
136 | stroke: #9370DB; | ||
137 | stroke-width: 1px; | ||
138 | } | ||
139 | |||
140 | #mermaidChart0 .flowchart-label text { | ||
141 | text-anchor: middle; | ||
142 | } | ||
143 | |||
144 | #mermaidChart0 .node .label { | ||
145 | text-align: center; | ||
146 | } | ||
147 | |||
148 | #mermaidChart0 .node.clickable { | ||
149 | cursor: pointer; | ||
150 | } | ||
151 | |||
152 | #mermaidChart0 .arrowheadPath { | ||
153 | fill: #333333; | ||
154 | } | ||
155 | |||
156 | #mermaidChart0 .edgePath .path { | ||
157 | stroke: #333333; | ||
158 | stroke-width: 2.0px; | ||
159 | } | ||
160 | |||
161 | #mermaidChart0 .flowchart-link { | ||
162 | stroke: #333333; | ||
163 | fill: none; | ||
164 | } | ||
165 | |||
166 | #mermaidChart0 .edgeLabel { | ||
167 | background-color: #e8e8e8; | ||
168 | text-align: center; | ||
169 | } | ||
170 | |||
171 | #mermaidChart0 .edgeLabel rect { | ||
172 | opacity: 0.5; | ||
173 | background-color: #e8e8e8; | ||
174 | fill: #e8e8e8; | ||
175 | } | ||
176 | |||
177 | #mermaidChart0 .labelBkg { | ||
178 | background-color: rgba(232, 232, 232, 0.5); | ||
179 | } | ||
180 | |||
181 | #mermaidChart0 .cluster rect { | ||
182 | fill: #ffffde; | ||
183 | stroke: #aaaa33; | ||
184 | stroke-width: 1px; | ||
185 | } | ||
186 | |||
187 | #mermaidChart0 .cluster text { | ||
188 | fill: #333; | ||
189 | } | ||
190 | |||
191 | #mermaidChart0 .cluster span, | ||
192 | #mermaidChart0 p { | ||
193 | color: #333; | ||
194 | } | ||
195 | |||
196 | #mermaidChart0 div.mermaidTooltip { | ||
197 | position: absolute; | ||
198 | text-align: center; | ||
199 | max-width: 200px; | ||
200 | padding: 2px; | ||
201 | font-family: sans-serif; | ||
202 | font-size: 12px; | ||
203 | background: hsl(80, 100%, 96.2745098039%); | ||
204 | border: 1px solid #aaaa33; | ||
205 | border-radius: 2px; | ||
206 | pointer-events: none; | ||
207 | z-index: 100; | ||
208 | } | ||
209 | |||
210 | #mermaidChart0 .flowchartTitleText { | ||
211 | text-anchor: middle; | ||
212 | font-size: 18px; | ||
213 | fill: #333; | ||
214 | } | ||
215 | |||
216 | #mermaidChart0 :root { | ||
217 | --mermaid-alt-font-family: sans-serif; | ||
218 | } | ||
219 | </style> | ||
220 | <g> | ||
221 | <marker id="mermaidChart0_flowchart-pointEnd" class="marker flowchart" viewBox="0 0 10 10" | ||
222 | refX="6" refY="5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12" | ||
223 | orient="auto"> | ||
224 | <path d="M 0 0 L 10 5 L 0 10 z" class="arrowMarkerPath" | ||
225 | style="stroke-width: 1; stroke-dasharray: 1, 0;"></path> | ||
226 | </marker> | ||
227 | <marker id="mermaidChart0_flowchart-pointStart" class="marker flowchart" viewBox="0 0 10 10" | ||
228 | refX="4.5" refY="5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12" | ||
229 | orient="auto"> | ||
230 | <path d="M 0 5 L 10 10 L 10 0 z" class="arrowMarkerPath" | ||
231 | style="stroke-width: 1; stroke-dasharray: 1, 0;"></path> | ||
232 | </marker> | ||
233 | <marker id="mermaidChart0_flowchart-circleEnd" class="marker flowchart" viewBox="0 0 10 10" | ||
234 | refX="11" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" | ||
235 | orient="auto"> | ||
236 | <circle cx="5" cy="5" r="5" class="arrowMarkerPath" | ||
237 | style="stroke-width: 1; stroke-dasharray: 1, 0;"></circle> | ||
238 | </marker> | ||
239 | <marker id="mermaidChart0_flowchart-circleStart" class="marker flowchart" viewBox="0 0 10 10" | ||
240 | refX="-1" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" | ||
241 | orient="auto"> | ||
242 | <circle cx="5" cy="5" r="5" class="arrowMarkerPath" | ||
243 | style="stroke-width: 1; stroke-dasharray: 1, 0;"></circle> | ||
244 | </marker> | ||
245 | <marker id="mermaidChart0_flowchart-crossEnd" class="marker cross flowchart" viewBox="0 0 11 11" | ||
246 | refX="12" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11" | ||
247 | orient="auto"> | ||
248 | <path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath" | ||
249 | style="stroke-width: 2; stroke-dasharray: 1, 0;"></path> | ||
250 | </marker> | ||
251 | <marker id="mermaidChart0_flowchart-crossStart" class="marker cross flowchart" | ||
252 | viewBox="0 0 11 11" refX="-1" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11" | ||
253 | markerHeight="11" orient="auto"> | ||
254 | <path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath" | ||
255 | style="stroke-width: 2; stroke-dasharray: 1, 0;"></path> | ||
256 | </marker> | ||
257 | <g class="root"> | ||
258 | <g class="clusters"></g> | ||
259 | <g class="edgePaths"> | ||
260 | <path d="M48.358,89.675L97.363,9.837L122.363,9.837L147.363,9.837L175.048,14.286" | ||
261 | id="L-N-I-0" | ||
262 | class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-N LE-I" | ||
263 | style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path> | ||
264 | <path d="M71.02,89.675L97.363,74.675L122.363,74.675L147.363,74.675L174.744,90.003" | ||
265 | id="L-N-V-0" | ||
266 | class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-N LE-V" | ||
267 | style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path> | ||
268 | <path d="M58.314,129.35L97.363,164.35L122.363,164.35L147.363,164.35L169.533,176.761" | ||
269 | id="L-N-R-0" | ||
270 | class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-N LE-R" | ||
271 | style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path> | ||
272 | <path d="M180.281,36.247L147.363,54.675L122.363,54.675L97.363,54.675L62.26,86.138" | ||
273 | id="L-I-N-0" | ||
274 | class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-I LE-N" | ||
275 | style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path> | ||
276 | <path d="M179.369,126.433L147.363,144.35L122.363,144.35L97.363,144.35L75.625,131.973" | ||
277 | id="L-V-N-0" | ||
278 | class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-V LE-N" | ||
279 | style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path> | ||
280 | <path d="M172.363,205.17L147.363,209.187L122.363,209.187L97.363,209.187L51.13,133.867" | ||
281 | id="L-R-N-0" | ||
282 | class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-R LE-N" | ||
283 | style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path> | ||
284 | </g> | ||
285 | <g class="edgeLabels"> | ||
286 | <g class="edgeLabel"> | ||
287 | <g class="label" transform="translate(0, 0)"> | ||
288 | <foreignObject width="0" height="0"> | ||
289 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
290 | style="display: inline-block; white-space: nowrap;"><span | ||
291 | class="edgeLabel"></span></div> | ||
292 | </foreignObject> | ||
293 | </g> | ||
294 | </g> | ||
295 | <g class="edgeLabel"> | ||
296 | <g class="label" transform="translate(0, 0)"> | ||
297 | <foreignObject width="0" height="0"> | ||
298 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
299 | style="display: inline-block; white-space: nowrap;"><span | ||
300 | class="edgeLabel"></span></div> | ||
301 | </foreignObject> | ||
302 | </g> | ||
303 | </g> | ||
304 | <g class="edgeLabel"> | ||
305 | <g class="label" transform="translate(0, 0)"> | ||
306 | <foreignObject width="0" height="0"> | ||
307 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
308 | style="display: inline-block; white-space: nowrap;"><span | ||
309 | class="edgeLabel"></span></div> | ||
310 | </foreignObject> | ||
311 | </g> | ||
312 | </g> | ||
313 | <g class="edgeLabel"> | ||
314 | <g class="label" transform="translate(0, 0)"> | ||
315 | <foreignObject width="0" height="0"> | ||
316 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
317 | style="display: inline-block; white-space: nowrap;"><span | ||
318 | class="edgeLabel"></span></div> | ||
319 | </foreignObject> | ||
320 | </g> | ||
321 | </g> | ||
322 | <g class="edgeLabel"> | ||
323 | <g class="label" transform="translate(0, 0)"> | ||
324 | <foreignObject width="0" height="0"> | ||
325 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
326 | style="display: inline-block; white-space: nowrap;"><span | ||
327 | class="edgeLabel"></span></div> | ||
328 | </foreignObject> | ||
329 | </g> | ||
330 | </g> | ||
331 | <g class="edgeLabel"> | ||
332 | <g class="label" transform="translate(0, 0)"> | ||
333 | <foreignObject width="0" height="0"> | ||
334 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
335 | style="display: inline-block; white-space: nowrap;"><span | ||
336 | class="edgeLabel"></span></div> | ||
337 | </foreignObject> | ||
338 | </g> | ||
339 | </g> | ||
340 | </g> | ||
341 | <g class="nodes"> | ||
342 | <g class="node default default flowchart-label" id="flowchart-N-0" | ||
343 | transform="translate(36.181251525878906, 109.51249885559082)"> | ||
344 | <rect class="basic label-container" style="" rx="5" ry="5" x="-36.18124961853027" | ||
345 | y="-19.83750057220459" width="72.36249923706055" height="39.67500114440918"> | ||
346 | </rect> | ||
347 | <g class="label" style="" | ||
348 | transform="translate(-28.681249618530273, -12.33750057220459)"> | ||
349 | <rect></rect> | ||
350 | <foreignObject width="57.36249923706055" height="24.67500114440918"> | ||
351 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
352 | style="display: inline-block; white-space: nowrap;"><span | ||
353 | class="nodeLabel">Normal</span></div> | ||
354 | </foreignObject> | ||
355 | </g> | ||
356 | </g> | ||
357 | <g class="node default default flowchart-label" id="flowchart-I-1" | ||
358 | transform="translate(209.59375381469727, 19.837499618530273)"> | ||
359 | <rect class="basic label-container" style="" rx="5" ry="5" x="-29.3125" | ||
360 | y="-19.83750057220459" width="58.625" height="39.67500114440918"></rect> | ||
361 | <g class="label" style="" transform="translate(-21.8125, -12.33750057220459)"> | ||
362 | <rect></rect> | ||
363 | <foreignObject width="43.625" height="24.67500114440918"> | ||
364 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
365 | style="display: inline-block; white-space: nowrap;"><span | ||
366 | class="nodeLabel">Insert</span></div> | ||
367 | </foreignObject> | ||
368 | </g> | ||
369 | </g> | ||
370 | <g class="node default default flowchart-label" id="flowchart-V-3" | ||
371 | transform="translate(209.59375381469727, 109.51249885559082)"> | ||
372 | <rect class="basic label-container" style="" rx="5" ry="5" x="-30.225000381469727" | ||
373 | y="-19.83750057220459" width="60.45000076293945" height="39.67500114440918"> | ||
374 | </rect> | ||
375 | <g class="label" style="" | ||
376 | transform="translate(-22.725000381469727, -12.33750057220459)"> | ||
377 | <rect></rect> | ||
378 | <foreignObject width="45.45000076293945" height="24.67500114440918"> | ||
379 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
380 | style="display: inline-block; white-space: nowrap;"><span | ||
381 | class="nodeLabel">Visual</span></div> | ||
382 | </foreignObject> | ||
383 | </g> | ||
384 | </g> | ||
385 | <g class="node default default flowchart-label" id="flowchart-R-5" | ||
386 | transform="translate(209.59375381469727, 199.18749809265137)"> | ||
387 | <rect class="basic label-container" style="" rx="5" ry="5" x="-37.23125076293945" | ||
388 | y="-19.83750057220459" width="74.4625015258789" height="39.67500114440918"> | ||
389 | </rect> | ||
390 | <g class="label" style="" | ||
391 | transform="translate(-29.731250762939453, -12.33750057220459)"> | ||
392 | <rect></rect> | ||
393 | <foreignObject width="59.462501525878906" height="24.67500114440918"> | ||
394 | <div xmlns="http://www.w3.org/1999/xhtml" | ||
395 | style="display: inline-block; white-space: nowrap;"><span | ||
396 | class="nodeLabel">Replace</span></div> | ||
397 | </foreignObject> | ||
398 | </g> | ||
399 | </g> | ||
400 | </g> | ||
401 | </g> | ||
402 | </g> | ||
403 | </svg></div> | ||
61 | <h1 id="我的-vim-学习路线">我的 vim 学习路线</h1> | 404 | <h1 id="我的-vim-学习路线">我的 vim 学习路线</h1> |
62 | <p>不幸的是 Vim 的学习曲线确实相当陡峭,最开始你会觉得非常不适应,但一旦熬过了初始阶段,你会爱上 Vim。以我而言,现在离开了 vim 的模式几乎已经快不会写材料了,前几天交作业要求 | 405 | <p>不幸的是 Vim 的学习曲线确实相当陡峭,最开始你会觉得非常不适应,但一旦熬过了初始阶段,你会爱上 Vim。以我而言,现在离开了 vim 的模式几乎已经快不会写材料了,前几天交作业要求 |
63 | word,我保存文件居然不是<kbd>Ctrl+s</kbd>,而是顺手来了个<kbd>:wq</kbd>。</p> | 406 | word,我保存文件居然不是<kbd>Ctrl+s</kbd>,而是顺手来了个<kbd>:wq</kbd>。</p> |
@@ -110,7 +453,6 @@ sudo apt autoremove python2*</code></pre> | |||
110 | <pre><code>sudo apt install -y git \ | 453 | <pre><code>sudo apt install -y git \ |
111 | libatk1.0-dev \ | 454 | libatk1.0-dev \ |
112 | libcairo2-dev \ | 455 | libcairo2-dev \ |
113 | #libgtk2.0-dev \ | ||
114 | liblua5.1-0-dev \ | 456 | liblua5.1-0-dev \ |
115 | libncurses5-dev \ | 457 | libncurses5-dev \ |
116 | libperl-dev \ | 458 | libperl-dev \ |
@@ -119,7 +461,8 @@ sudo apt autoremove python2*</code></pre> | |||
119 | libxt-dev \ | 461 | libxt-dev \ |
120 | lua5.1 \ | 462 | lua5.1 \ |
121 | python3-dev \ | 463 | python3-dev \ |
122 | ruby-dev</code></pre> | 464 | ruby-dev \ |
465 | # libgtk2.0-dev</code></pre> | ||
123 | <p>由于我的编译在服务器上运行,主要运行环境为命令行,不需要 gtk2 等图形界面的支持,因而将安装 gtk 的那一行注释掉了。在编译带有 gtk2.0 的 vim 时似乎会遇到问题:vim | 466 | <p>由于我的编译在服务器上运行,主要运行环境为命令行,不需要 gtk2 等图形界面的支持,因而将安装 gtk 的那一行注释掉了。在编译带有 gtk2.0 的 vim 时似乎会遇到问题:vim |
124 | 源码截至目前版本(v9.0.1854)采用的 gtk 代码中的<code>struct _GTimeVal</code>已经被弃用,gcc | 467 | 源码截至目前版本(v9.0.1854)采用的 gtk 代码中的<code>struct _GTimeVal</code>已经被弃用,gcc |
125 | 要求改用<code>struct _GDateTime</code>,因此编译时会报错,而且陷入死循环,编译不会终止,只能<kbd>Ctrl+c</kbd>杀死进程。我尚不知道如何解决。这也是我放弃支持 | 468 | 要求改用<code>struct _GDateTime</code>,因此编译时会报错,而且陷入死循环,编译不会终止,只能<kbd>Ctrl+c</kbd>杀死进程。我尚不知道如何解决。这也是我放弃支持 |
diff --git a/code/linux/vim.md b/code/linux/vim.md index ec32d67..4d21b25 100644 --- a/code/linux/vim.md +++ b/code/linux/vim.md | |||
@@ -76,7 +76,6 @@ sudo apt autoremove python2* | |||
76 | sudo apt install -y git \ | 76 | sudo apt install -y git \ |
77 | libatk1.0-dev \ | 77 | libatk1.0-dev \ |
78 | libcairo2-dev \ | 78 | libcairo2-dev \ |
79 | #libgtk2.0-dev \ | ||
80 | liblua5.1-0-dev \ | 79 | liblua5.1-0-dev \ |
81 | libncurses5-dev \ | 80 | libncurses5-dev \ |
82 | libperl-dev \ | 81 | libperl-dev \ |
@@ -85,7 +84,8 @@ sudo apt install -y git \ | |||
85 | libxt-dev \ | 84 | libxt-dev \ |
86 | lua5.1 \ | 85 | lua5.1 \ |
87 | python3-dev \ | 86 | python3-dev \ |
88 | ruby-dev | 87 | ruby-dev \ |
88 | # libgtk2.0-dev | ||
89 | ``` | 89 | ``` |
90 | 90 | ||
91 | 由于我的编译在服务器上运行,主要运行环境为命令行,不需要 gtk2 等图形界面的支持,因而将安装 gtk 的那一行注释掉了。在编译带有 gtk2.0 的 vim 时似乎会遇到问题:vim 源码截至目前版本(v9.0.1854)采用的 gtk 代码中的`struct _GTimeVal`已经被弃用,gcc 要求改用`struct _GDateTime`,因此编译时会报错,而且陷入死循环,编译不会终止,只能<kbd>Ctrl+c</kbd>杀死进程。我尚不知道如何解决。这也是我放弃支持 gtk 的原因之一。 | 91 | 由于我的编译在服务器上运行,主要运行环境为命令行,不需要 gtk2 等图形界面的支持,因而将安装 gtk 的那一行注释掉了。在编译带有 gtk2.0 的 vim 时似乎会遇到问题:vim 源码截至目前版本(v9.0.1854)采用的 gtk 代码中的`struct _GTimeVal`已经被弃用,gcc 要求改用`struct _GDateTime`,因此编译时会报错,而且陷入死循环,编译不会终止,只能<kbd>Ctrl+c</kbd>杀死进程。我尚不知道如何解决。这也是我放弃支持 gtk 的原因之一。 |
diff --git a/code/ohos/ohos_compile.html b/code/ohos/ohos_compile.html index 4a77d32..6d6b3ce 100644 --- a/code/ohos/ohos_compile.html +++ b/code/ohos/ohos_compile.html | |||
@@ -5,8 +5,9 @@ | |||
5 | <meta charset="utf-8" /> | 5 | <meta charset="utf-8" /> |
6 | <meta name="generator" content="pandoc" /> | 6 | <meta name="generator" content="pandoc" /> |
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
8 | <title>OpenHarmony 3.2 编译</title> | 8 | <title>Open Harmony 编译</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
11 | </head> | 12 | </head> |
12 | 13 | ||
@@ -14,7 +15,7 @@ | |||
14 | <div class="pandoc"> | 15 | <div class="pandoc"> |
15 | <div class="main"> | 16 | <div class="main"> |
16 | <header id="title-block-header"> | 17 | <header id="title-block-header"> |
17 | <p class="title">OpenHarmony 3.2 编译</h1> | 18 | <p class="title">Open Harmony 编译</p> |
18 | </header> | 19 | </header> |
19 | <!-- 鸿蒙开发环境搭建 --> | 20 | <!-- 鸿蒙开发环境搭建 --> |
20 | <blockquote> | 21 | <blockquote> |
@@ -115,9 +116,16 @@ ssh-keygen -t rsa -C "your-email-address"</code></pre> | |||
115 | <p>在 gitee 用户的设置界面,将公钥<code>id_rsa.pub</code>的内容复制到 gitee 的 SSH 公钥中,保存即可。</p> | 116 | <p>在 gitee 用户的设置界面,将公钥<code>id_rsa.pub</code>的内容复制到 gitee 的 SSH 公钥中,保存即可。</p> |
116 | <p>此时,我们就可以通过 ssh 的方式与 gitee 进行交互、也可以免密提交代码了。</p> | 117 | <p>此时,我们就可以通过 ssh 的方式与 gitee 进行交互、也可以免密提交代码了。</p> |
117 | <h1 id="配置-repo-工具">配置 repo 工具</h1> | 118 | <h1 id="配置-repo-工具">配置 repo 工具</h1> |
118 | <pre><code>sudo curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo | 119 | <p><strong>注意:前两条命令需要以 root 身份执行!!!</strong></p> |
119 | sudo chmod a+x /usr/local/bin/repo | 120 | <pre><code># 以下两条命令需要以root身份执行 |
121 | curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo | ||
122 | chmod a+x /usr/local/bin/repo | ||
123 | |||
124 | # 这条普通身份也可以 | ||
120 | pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests</code></pre> | 125 | pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests</code></pre> |
126 | <p>之所以前两条命令需要以 root 身份而不能是 sudo,是因为<code>/usr/local/bin</code>是一个只有 root 用户才有写权限的目录,而 sudo 命令虽然是以 root | ||
127 | 身份执行,但<strong>重定向时候 sudo 用的也是当前用户身份</strong>,权限不足,自然报错。(<strong>如果是管道,那么 sudo | ||
128 | 也是只对当前命令有效,而不是对后续的整个管道有效。</strong>)</p> | ||
121 | <h1 id="系统源码编译">系统源码编译</h1> | 129 | <h1 id="系统源码编译">系统源码编译</h1> |
122 | <h2 id="获取源码">获取源码</h2> | 130 | <h2 id="获取源码">获取源码</h2> |
123 | <p>通过 repo + https/ssh 下载:</p> | 131 | <p>通过 repo + https/ssh 下载:</p> |
diff --git a/code/ohos/ohos_compile.md b/code/ohos/ohos_compile.md index a26fb28..e7d2359 100644 --- a/code/ohos/ohos_compile.md +++ b/code/ohos/ohos_compile.md | |||
@@ -109,12 +109,19 @@ ssh-keygen -t rsa -C "your-email-address" | |||
109 | 109 | ||
110 | # 配置 repo 工具 | 110 | # 配置 repo 工具 |
111 | 111 | ||
112 | **注意:前两条命令需要以 root 身份执行!!!** | ||
113 | |||
112 | ```bash | 114 | ```bash |
113 | sudo curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo | 115 | # 以下两条命令需要以root身份执行 |
114 | sudo chmod a+x /usr/local/bin/repo | 116 | curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo |
117 | chmod a+x /usr/local/bin/repo | ||
118 | |||
119 | # 这条普通身份也可以 | ||
115 | pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests | 120 | pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests |
116 | ``` | 121 | ``` |
117 | 122 | ||
123 | 之所以前两条命令需要以 root 身份而不能是 sudo,是因为`/usr/local/bin`是一个只有 root 用户才有写权限的目录,而 sudo 命令虽然是以 root 身份执行,但**重定向时候 sudo 用的也是当前用户身份**,权限不足,自然报错。(**如果是管道,那么 sudo 也是只对当前命令有效,而不是对后续的整个管道有效。**) | ||
124 | |||
118 | # 系统源码编译 | 125 | # 系统源码编译 |
119 | 126 | ||
120 | ## 获取源码 | 127 | ## 获取源码 |
diff --git a/common/CSS/MySet.css b/common/CSS/MySet.css index e152141..c40e588 100644 --- a/common/CSS/MySet.css +++ b/common/CSS/MySet.css | |||
@@ -104,4 +104,18 @@ a { | |||
104 | .comment hr { | 104 | .comment hr { |
105 | margin-top: 50px; | 105 | margin-top: 50px; |
106 | margin-bottom: 40px; | 106 | margin-bottom: 40px; |
107 | } \ No newline at end of file | 107 | } |
108 | |||
109 | /* 为class为"markmap mindmap"的元素设计圆角矩形边框 */ | ||
110 | .markmap.mindmap { | ||
111 | border: 1px solid #000; | ||
112 | padding: 10px; | ||
113 | margin: 10px; | ||
114 | border-radius: 50px; | ||
115 | } | ||
116 | |||
117 | /* .markmap.mindmap { | ||
118 | border: 1px solid #000; | ||
119 | padding: 10px; | ||
120 | margin: 10px; | ||
121 | } */ \ No newline at end of file | ||
diff --git a/common/CSS/github.css b/common/CSS/github.css index 3fa8aa3..d3b5158 100644 --- a/common/CSS/github.css +++ b/common/CSS/github.css | |||
@@ -1840,4 +1840,6 @@ footer { | |||
1840 | .menu-item-container a.menu-style-btn { | 1840 | .menu-item-container a.menu-style-btn { |
1841 | background-color: #f5f8fa; | 1841 | background-color: #f5f8fa; |
1842 | background-image: linear-gradient(180deg, hsla(0, 0%, 100%, 0.8), hsla(0, 0%, 100%, 0)); | 1842 | background-image: linear-gradient(180deg, hsla(0, 0%, 100%, 0.8), hsla(0, 0%, 100%, 0)); |
1843 | } \ No newline at end of file | 1843 | } |
1844 | |||
1845 | /* code标签下的table, */ \ No newline at end of file | ||
diff --git a/common/CSS/huang.css b/common/CSS/huang.css index 62fdccf..da7de81 100644 --- a/common/CSS/huang.css +++ b/common/CSS/huang.css | |||
@@ -10,7 +10,7 @@ body { | |||
10 | } | 10 | } |
11 | 11 | ||
12 | .sidenav { | 12 | .sidenav { |
13 | height: 91.5%; | 13 | height: 95%; |
14 | width: 0; | 14 | width: 0; |
15 | position: fixed; | 15 | position: fixed; |
16 | z-index: 1; | 16 | z-index: 1; |
@@ -19,7 +19,7 @@ body { | |||
19 | background-color: #111; | 19 | background-color: #111; |
20 | overflow-x: hidden; | 20 | overflow-x: hidden; |
21 | transition: .5s; | 21 | transition: .5s; |
22 | padding-top: 60px | 22 | padding-top: 40px |
23 | } | 23 | } |
24 | 24 | ||
25 | .sidenav a { | 25 | .sidenav a { |
@@ -81,7 +81,8 @@ h3 { | |||
81 | } | 81 | } |
82 | 82 | ||
83 | .icon { | 83 | .icon { |
84 | padding: 1rem 0 0 0 | 84 | /* padding: 1rem 0 0 0; */ |
85 | padding: 0 0 10px 0; | ||
85 | } | 86 | } |
86 | 87 | ||
87 | .icon svg { | 88 | .icon svg { |
diff --git a/common/CSS/pandoc.css b/common/CSS/pandoc.css index 61ad2c1..b376205 100644 --- a/common/CSS/pandoc.css +++ b/common/CSS/pandoc.css | |||
@@ -144,9 +144,6 @@ table { | |||
144 | /* 改的 */ | 144 | /* 改的 */ |
145 | display: inline; | 145 | display: inline; |
146 | text-align: left; | 146 | text-align: left; |
147 | /* 表格本身居中显示 */ | ||
148 | margin-left: auto; | ||
149 | margin-right: auto; | ||
150 | } | 147 | } |
151 | 148 | ||
152 | table caption { | 149 | table caption { |
diff --git a/common/script4code.html b/common/script4code.html index 6d0caa2..9de3349 100644 --- a/common/script4code.html +++ b/common/script4code.html | |||
@@ -9,13 +9,12 @@ | |||
9 | <script src="https://www.qin-juan-ge-zhu.top/common/js/jQuery.js"></script> | 9 | <script src="https://www.qin-juan-ge-zhu.top/common/js/jQuery.js"></script> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/vim.js"></script> | 10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/vim.js"></script> |
11 | <!-- <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/click4code.js"></script> --> | 11 | <!-- <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/click4code.js"></script> --> |
12 | <script src="https://www.qin-juan-ge-zhu.top/common/js/click4notes.js"></script> | ||
12 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/pandoc-menu.js"></script> | 13 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/pandoc-menu.js"></script> |
13 | <script src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
14 | </head> | 14 | </head> |
15 | 15 | ||
16 | <body class='typora-export os-windows'> | 16 | <body class='typora-export os-windows'> |
17 | <!-- <div class="yanhua"></div> --> | 17 | <!-- <div class="yanhua"></div> --> |
18 | <script src="https://www.qin-juan-ge-zhu.top/common/js/click4notes.js"></script> | ||
19 | <script type="text/javascript"> | 18 | <script type="text/javascript"> |
20 | //生成随机颜色 | 19 | //生成随机颜色 |
21 | function randomColor() { | 20 | function randomColor() { |
diff --git a/common/script4code.js b/common/script4code.js index d9fe85b..19fda0e 100644 --- a/common/script4code.js +++ b/common/script4code.js | |||
@@ -9,13 +9,12 @@ document.writeln(" <link rel=\"icon\" type=\"image/x-icon\" href=\"https://ww | |||
9 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/jQuery.js\"></script>"); | 9 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/jQuery.js\"></script>"); |
10 | document.writeln(" <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/vim.js\"></script>"); | 10 | document.writeln(" <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/vim.js\"></script>"); |
11 | document.writeln(" <!-- <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/click4code.js\"></script> -->"); | 11 | document.writeln(" <!-- <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/click4code.js\"></script> -->"); |
12 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/click4notes.js\"></script>"); | ||
12 | document.writeln(" <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/pandoc-menu.js\"></script>"); | 13 | document.writeln(" <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/pandoc-menu.js\"></script>"); |
13 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js\"></script>"); | ||
14 | document.writeln("</head>"); | 14 | document.writeln("</head>"); |
15 | document.writeln(""); | 15 | document.writeln(""); |
16 | document.writeln("<body class=\'typora-export os-windows\'>"); | 16 | document.writeln("<body class=\'typora-export os-windows\'>"); |
17 | document.writeln(" <!-- <div class=\"yanhua\"></div> -->"); | 17 | document.writeln(" <!-- <div class=\"yanhua\"></div> -->"); |
18 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/click4notes.js\"></script>"); | ||
19 | document.writeln(" <script type=\"text/javascript\">"); | 18 | document.writeln(" <script type=\"text/javascript\">"); |
20 | document.writeln(" //生成随机颜色"); | 19 | document.writeln(" //生成随机颜色"); |
21 | document.writeln(" function randomColor() {"); | 20 | document.writeln(" function randomColor() {"); |
diff --git a/common/script4works.html b/common/script4works.html index ba75e1c..478adc9 100644 --- a/common/script4works.html +++ b/common/script4works.html | |||
@@ -9,7 +9,12 @@ | |||
9 | <link id="giscus-css" rel="stylesheet" href="https://giscus.app/default.css"> | 9 | <link id="giscus-css" rel="stylesheet" href="https://giscus.app/default.css"> |
10 | <script src="https://www.qin-juan-ge-zhu.top/common/js/jQuery.js"></script> | 10 | <script src="https://www.qin-juan-ge-zhu.top/common/js/jQuery.js"></script> |
11 | <script src="https://www.qin-juan-ge-zhu.top/common/js/huang.js"></script> | 11 | <script src="https://www.qin-juan-ge-zhu.top/common/js/huang.js"></script> |
12 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/vim.js"></script> | 12 | <script src="https://www.qin-juan-ge-zhu.top/common/js/click4code.js"></script> |
13 | <!-- FIXME: | ||
14 | vim快捷键与valine评论区(即comment4works)冲突 | ||
15 | 在评论区键入hjk字符时,仍然会触发页面快捷键, | ||
16 | 导致无法正常键入,并影响使用体验 --> | ||
17 | <!-- <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/vim.js"></script> --> | ||
13 | <style> | 18 | <style> |
14 | .main-menu { | 19 | .main-menu { |
15 | font-size: 30px !important; | 20 | font-size: 30px !important; |
@@ -49,8 +54,14 @@ | |||
49 | </head> | 54 | </head> |
50 | 55 | ||
51 | <body class="typora-export os-windows"> | 56 | <body class="typora-export os-windows"> |
52 | <div class="yanhua"></div> | 57 | <!-- FIXME: |
53 | <!-- <script src="https://www.qin-juan-ge-zhu.top/common/js/click4works.js"></script> --> | 58 | 对于scripr4works而言,鼠标在页面上部点击时,效果正常,是在鼠标位置展示 |
59 | 但对于内容的下部,会出现展示位置在鼠标下方一段距离,越靠下越严重 | ||
60 | 而评论区分界线以下更是完全不展示 | ||
61 | 故本页面在head里暂借没有页面使用的click4code充当点击效果 | ||
62 | 嗣后效果修复完成,js不要在head里用,就在yanhua底下即可,不然还要加onload --> | ||
63 | <!-- <div class="yanhua"></div> | ||
64 | <script src="https://www.qin-juan-ge-zhu.top/common/js/click4works.js"></script> --> | ||
54 | <div id="mySidenav" class="sidenav" style="width: 0px;"> | 65 | <div id="mySidenav" class="sidenav" style="width: 0px;"> |
55 | <div class="sidebar" name="sizebar"> | 66 | <div class="sidebar" name="sizebar"> |
56 | <div class="sidebar" name="sizebar"> | 67 | <div class="sidebar" name="sizebar"> |
@@ -138,12 +149,12 @@ | |||
138 | </div> | 149 | </div> |
139 | <a onclick="clickit('grandson22')">-一些小玩意儿</a> | 150 | <a onclick="clickit('grandson22')">-一些小玩意儿</a> |
140 | <div class="grandson" id="grandson22" style="display: none;"> | 151 | <div class="grandson" id="grandson22" style="display: none;"> |
141 | <a href="https://www.qin-juan-ge-zhu.top/code/ohos/ohos_compile.html">OpenHarmony 3.2 <br>编译</a> | 152 | <a href="https://www.qin-juan-ge-zhu.top/code/ohos/ohos_compile.html">OpenHarmony编译</a> |
142 | <a href="https://www.qin-juan-ge-zhu.top/code/highlight.html">代码高亮与复制</a> | 153 | <a href="https://www.qin-juan-ge-zhu.top/code/highlight.html">代码高亮与复制</a> |
143 | <a href="https://www.qin-juan-ge-zhu.top/code/index.html">C的小零件</a> | 154 | <a href="https://www.qin-juan-ge-zhu.top/code/index.html">C的小零件</a> |
144 | <a href="https://www.qin-juan-ge-zhu.top/code/cpppp.html">C++ Primer Plus基础</a> | 155 | <a href="https://www.qin-juan-ge-zhu.top/code/cpppp.html">C++ Primer Plus基础</a> |
145 | <a href="https://www.qin-juan-ge-zhu.top/code/fileop(cpp).html">C++文件操作</a> | 156 | <a href="https://www.qin-juan-ge-zhu.top/code/fileop(cpp).html">C++文件操作</a> |
146 | <a href="https://www.qin-juan-ge-zhu.top/code/experiment">大物实验MATLAB</a> | 157 | <a href="https://www.qin-juan-ge-zhu.top/code/experiment.html">大物实验MATLAB</a> |
147 | <a href="https://www.qin-juan-ge-zhu.top/code/zeal.html">Zeal文档下载</a> | 158 | <a href="https://www.qin-juan-ge-zhu.top/code/zeal.html">Zeal文档下载</a> |
148 | </div> | 159 | </div> |
149 | <a onclick="clickit('grandson23')">-功能网页</a> | 160 | <a onclick="clickit('grandson23')">-功能网页</a> |
@@ -202,9 +213,7 @@ | |||
202 | fill="white"></path> | 213 | fill="white"></path> |
203 | </svg></a> | 214 | </svg></a> |
204 | <footer class="footer" style="font-size: large;"> | 215 | <footer class="footer" style="font-size: large;"> |
205 | <!-- <a class="copyright" href="https://www.qin-juan-ge-zhu.top/courseNotes" target="_blank"> --> | 216 | 勤倦閣 |
206 | 勤倦閣 | ||
207 | <!-- </a> --> | ||
208 | </footer> | 217 | </footer> |
209 | </body> | 218 | </body> |
210 | 219 | ||
diff --git a/common/script4works.js b/common/script4works.js index 861a074..3327557 100644 --- a/common/script4works.js +++ b/common/script4works.js | |||
@@ -9,7 +9,12 @@ document.writeln(" <link rel=\"icon\" type=\"image/x-icon\" href=\"https://ww | |||
9 | document.writeln(" <link id=\"giscus-css\" rel=\"stylesheet\" href=\"https://giscus.app/default.css\">"); | 9 | document.writeln(" <link id=\"giscus-css\" rel=\"stylesheet\" href=\"https://giscus.app/default.css\">"); |
10 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/jQuery.js\"></script>"); | 10 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/jQuery.js\"></script>"); |
11 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/huang.js\"></script>"); | 11 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/huang.js\"></script>"); |
12 | document.writeln(" <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/vim.js\"></script>"); | 12 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/click4code.js\"></script>"); |
13 | document.writeln(" <!-- FIXME:"); | ||
14 | document.writeln(" vim快捷键与valine评论区(即comment4works)冲突"); | ||
15 | document.writeln(" 在评论区键入hjk字符时,仍然会触发页面快捷键,"); | ||
16 | document.writeln(" 导致无法正常键入,并影响使用体验 -->"); | ||
17 | document.writeln(" <!-- <script type=\"text/javascript\" src=\"https://www.qin-juan-ge-zhu.top/common/js/vim.js\"></script> -->"); | ||
13 | document.writeln(" <style>"); | 18 | document.writeln(" <style>"); |
14 | document.writeln(" .main-menu {"); | 19 | document.writeln(" .main-menu {"); |
15 | document.writeln(" font-size: 30px !important;"); | 20 | document.writeln(" font-size: 30px !important;"); |
@@ -49,8 +54,14 @@ document.writeln(" </script>"); | |||
49 | document.writeln("</head>"); | 54 | document.writeln("</head>"); |
50 | document.writeln(""); | 55 | document.writeln(""); |
51 | document.writeln("<body class=\"typora-export os-windows\">"); | 56 | document.writeln("<body class=\"typora-export os-windows\">"); |
52 | document.writeln(" <div class=\"yanhua\"></div>"); | 57 | document.writeln(" <!-- FIXME:"); |
53 | document.writeln(" <!-- <script src=\"https://www.qin-juan-ge-zhu.top/common/js/click4works.js\"></script> -->"); | 58 | document.writeln(" 对于scripr4works而言,鼠标在页面上部点击时,效果正常,是在鼠标位置展示"); |
59 | document.writeln(" 但对于内容的下部,会出现展示位置在鼠标下方一段距离,越靠下越严重"); | ||
60 | document.writeln(" 而评论区分界线以下更是完全不展示"); | ||
61 | document.writeln(" 故本页面在head里暂借没有页面使用的click4code充当点击效果"); | ||
62 | document.writeln(" 嗣后效果修复完成,js不要在head里用,就在yanhua底下即可,不然还要加onload -->"); | ||
63 | document.writeln(" <!-- <div class=\"yanhua\"></div>"); | ||
64 | document.writeln(" <script src=\"https://www.qin-juan-ge-zhu.top/common/js/click4works.js\"></script> -->"); | ||
54 | document.writeln(" <div id=\"mySidenav\" class=\"sidenav\" style=\"width: 0px;\">"); | 65 | document.writeln(" <div id=\"mySidenav\" class=\"sidenav\" style=\"width: 0px;\">"); |
55 | document.writeln(" <div class=\"sidebar\" name=\"sizebar\">"); | 66 | document.writeln(" <div class=\"sidebar\" name=\"sizebar\">"); |
56 | document.writeln(" <div class=\"sidebar\" name=\"sizebar\">"); | 67 | document.writeln(" <div class=\"sidebar\" name=\"sizebar\">"); |
@@ -139,12 +150,12 @@ document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code | |||
139 | document.writeln(" </div>"); | 150 | document.writeln(" </div>"); |
140 | document.writeln(" <a onclick=\"clickit(\'grandson22\')\">-一些小玩意儿</a>"); | 151 | document.writeln(" <a onclick=\"clickit(\'grandson22\')\">-一些小玩意儿</a>"); |
141 | document.writeln(" <div class=\"grandson\" id=\"grandson22\" style=\"display: none;\">"); | 152 | document.writeln(" <div class=\"grandson\" id=\"grandson22\" style=\"display: none;\">"); |
142 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/ohos/ohos_compile.html\">OpenHarmony 3.2 <br>编译</a>"); | 153 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/ohos/ohos_compile.html\">OpenHarmony编译</a>"); |
143 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/highlight.html\">代码高亮与复制</a>"); | 154 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/highlight.html\">代码高亮与复制</a>"); |
144 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/index.html\">C的小零件</a>"); | 155 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/index.html\">C的小零件</a>"); |
145 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/cpppp.html\">C++ Primer Plus基础</a>"); | 156 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/cpppp.html\">C++ Primer Plus基础</a>"); |
146 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/fileop(cpp).html\">C++文件操作</a>"); | 157 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/fileop(cpp).html\">C++文件操作</a>"); |
147 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/experiment\">大物实验MATLAB</a>"); | 158 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/experiment.html\">大物实验MATLAB</a>"); |
148 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/zeal.html\">Zeal文档下载</a>"); | 159 | document.writeln(" <a href=\"https://www.qin-juan-ge-zhu.top/code/zeal.html\">Zeal文档下载</a>"); |
149 | document.writeln(" </div>"); | 160 | document.writeln(" </div>"); |
150 | document.writeln(" <a onclick=\"clickit(\'grandson23\')\">-功能网页</a>"); | 161 | document.writeln(" <a onclick=\"clickit(\'grandson23\')\">-功能网页</a>"); |
@@ -203,9 +214,7 @@ document.writeln(" d=\"M115.0,115.0 C114.9,115.1 118.7,116.5 119. | |||
203 | document.writeln(" fill=\"white\"></path>"); | 214 | document.writeln(" fill=\"white\"></path>"); |
204 | document.writeln(" </svg></a>"); | 215 | document.writeln(" </svg></a>"); |
205 | document.writeln(" <footer class=\"footer\" style=\"font-size: large;\">"); | 216 | document.writeln(" <footer class=\"footer\" style=\"font-size: large;\">"); |
206 | document.writeln(" <!-- <a class=\"copyright\" href=\"https://www.qin-juan-ge-zhu.top/courseNotes\" target=\"_blank\"> -->"); | 217 | document.writeln(" 勤倦閣"); |
207 | document.writeln(" 勤倦閣"); | ||
208 | document.writeln(" <!-- </a> -->"); | ||
209 | document.writeln(" </footer>"); | 218 | document.writeln(" </footer>"); |
210 | document.writeln("</body>"); | 219 | document.writeln("</body>"); |
211 | document.writeln(""); | 220 | document.writeln(""); |
diff --git a/courseNotes/Xi'ism.html b/courseNotes/Xi'ism.html index db83ceb..ad292ff 100644 --- a/courseNotes/Xi'ism.html +++ b/courseNotes/Xi'ism.html | |||
@@ -4752,6 +4752,7 @@ | |||
4752 | {} | 4752 | {} |
4753 | ); | 4753 | ); |
4754 | </script> | 4754 | </script> |
4755 | <p class="time">2022.12</p> | ||
4755 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment4works.js"></script> | 4756 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment4works.js"></script> |
4756 | </div> | 4757 | </div> |
4757 | </div> | 4758 | </div> |
diff --git a/courseNotes/git/ShangGuiGu.html b/courseNotes/git/ShangGuiGu.html index 8c3ce9d..3282e00 100644 --- a/courseNotes/git/ShangGuiGu.html +++ b/courseNotes/git/ShangGuiGu.html | |||
@@ -2,38 +2,1203 @@ | |||
2 | <html> | 2 | <html> |
3 | 3 | ||
4 | <head> | 4 | <head> |
5 | <meta charset="UTF-8"> | 5 | <meta charset="UTF-8" /> |
6 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
7 | <meta http-equiv="X-UA-Compatible" content="ie=edge"> | 7 | <meta http-equiv="X-UA-Compatible" content="ie=edge" /> |
8 | <title>尚硅谷git笔记</title> | 8 | <title>尚硅谷git笔记</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/github.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/github.css" /> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
11 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/markmap-toolbar@0.14.3/dist/style.css"> | 11 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/markmap-toolbar@0.14.3/dist/style.css" /> |
12 | </head> | 12 | </head> |
13 | 13 | ||
14 | <body class='typora-export os-windows'> | 14 | <body class="typora-export os-windows"> |
15 | <div class='typora-export-content'> | 15 | <div class="typora-export-content"> |
16 | <div id='write'> | 16 | <div id="write"> |
17 | <p class="title">尚硅谷git笔记</p> | 17 | <p class="title">尚硅谷git笔记</p> |
18 | <p class="time"><a | 18 | <p class="time"> |
19 | <a | ||
19 | href="https://www.bilibili.com/video/BV1vy4y1s7k6/?vd_source=0e7576154715d4dea629f3e001cde0ae">课程网址</a> | 20 | href="https://www.bilibili.com/video/BV1vy4y1s7k6/?vd_source=0e7576154715d4dea629f3e001cde0ae">课程网址</a> |
20 | </p> | 21 | </p> |
21 | <p class="time">本思维导图使用<a href="https://markmap.js.org/">Markmap</a>制作</p> | 22 | <p class="time"> |
22 | <p class="time" style="text-align: left;">说明:</p> | 23 | 本思维导图使用<a href="https://markmap.js.org/">Markmap</a>制作 |
23 | <p class="time" style="text-align: left;">课程使用大量篇幅讲解GitHub基本操作,选择性记录;</p> | ||
24 | <p class="time" style="text-align: left;">讲解Idea对Git/GitHub/Gitee的集成,没用过,不记录;</p> | ||
25 | <p class="time" style="text-align: left;">讲解局域网代码托管平台GitLab服务器的搭建,暂时用不着,不记录。 | ||
26 | </p> | 24 | </p> |
25 | <p class="time" style="text-align: left">说明:</p> | ||
26 | <p class="time" style="text-align: left"> | ||
27 | 课程使用大量篇幅讲解GitHub基本操作,选择性记录; | ||
28 | </p> | ||
29 | <p class="time" style="text-align: left"> | ||
30 | 讲解Idea对Git/GitHub/Gitee的集成,没用过,不记录; | ||
31 | </p> | ||
32 | <p class="time" style="text-align: left"> | ||
33 | 讲解局域网代码托管平台GitLab服务器的搭建,暂时用不着,不记录。 | ||
34 | </p> | ||
35 | <svg id="mindmap"></svg> | ||
36 | <script src="https://cdn.jsdelivr.net/npm/d3@6.7.0"></script> | ||
37 | <script src="https://cdn.jsdelivr.net/npm/markmap-view@0.14.3"></script> | ||
38 | <script src="https://cdn.jsdelivr.net/npm/markmap-toolbar@0.14.3/dist/index.umd.min.js"></script> | ||
39 | <script> | ||
40 | ((getMarkmap, getOptions, root, jsonOptions) => { | ||
41 | const markmap = getMarkmap(); | ||
42 | window.mm = markmap.Markmap.create( | ||
43 | "svg#mindmap", | ||
44 | (getOptions || markmap.deriveOptions)(jsonOptions), | ||
45 | root | ||
46 | ); | ||
47 | })( | ||
48 | () => window.markmap, | ||
49 | null, | ||
50 | { | ||
51 | type: "heading", | ||
52 | depth: 0, | ||
53 | payload: { lines: [0, 1] }, | ||
54 | content: "Git", | ||
55 | children: [ | ||
56 | { | ||
57 | type: "bullet_list", | ||
58 | depth: 1, | ||
59 | payload: { lines: [1, 2] }, | ||
60 | content: "", | ||
61 | children: [ | ||
62 | { | ||
63 | type: "list_item", | ||
64 | depth: 2, | ||
65 | payload: { lines: [1, 2] }, | ||
66 | content: "课程目标:5h熟练掌握以下内容", | ||
67 | }, | ||
68 | ], | ||
69 | }, | ||
70 | { | ||
71 | type: "heading", | ||
72 | depth: 1, | ||
73 | payload: { lines: [2, 3] }, | ||
74 | content: "Git介绍", | ||
75 | children: [ | ||
76 | { | ||
77 | type: "heading", | ||
78 | depth: 2, | ||
79 | payload: { lines: [3, 4] }, | ||
80 | content: "免费的开源分布式VCS", | ||
81 | children: [ | ||
82 | { | ||
83 | type: "heading", | ||
84 | depth: 3, | ||
85 | payload: { lines: [4, 5] }, | ||
86 | content: "版本控制", | ||
87 | children: [ | ||
88 | { | ||
89 | type: "list_item", | ||
90 | depth: 4, | ||
91 | payload: { lines: [5, 6] }, | ||
92 | content: "记录文件内容变化", | ||
93 | }, | ||
94 | { | ||
95 | type: "list_item", | ||
96 | depth: 4, | ||
97 | payload: { lines: [6, 7] }, | ||
98 | content: "查阅特定历史版本", | ||
99 | }, | ||
100 | { | ||
101 | type: "list_item", | ||
102 | depth: 4, | ||
103 | payload: { lines: [7, 8] }, | ||
104 | content: | ||
105 | "记录文件修改的历史记录、查看历史版本、作版本切换", | ||
106 | }, | ||
107 | { | ||
108 | type: "list_item", | ||
109 | depth: 4, | ||
110 | payload: { lines: [8, 9] }, | ||
111 | content: "个人开发过渡到团队协作的需求", | ||
112 | }, | ||
113 | ], | ||
114 | }, | ||
115 | { | ||
116 | type: "heading", | ||
117 | depth: 3, | ||
118 | payload: { lines: [9, 10] }, | ||
119 | content: "分布式VCS VS 集中式VCS", | ||
120 | children: [ | ||
121 | { | ||
122 | type: "list_item", | ||
123 | depth: 4, | ||
124 | payload: { lines: [10, 11] }, | ||
125 | content: "集中的版本控制工具", | ||
126 | children: [ | ||
127 | { | ||
128 | type: "list_item", | ||
129 | depth: 5, | ||
130 | payload: { lines: [11, 12] }, | ||
131 | content: "CVS/SVN", | ||
132 | }, | ||
133 | { | ||
134 | type: "list_item", | ||
135 | depth: 5, | ||
136 | payload: { lines: [12, 13] }, | ||
137 | content: "中央服务器", | ||
138 | }, | ||
139 | { | ||
140 | type: "list_item", | ||
141 | depth: 5, | ||
142 | payload: { lines: [13, 14] }, | ||
143 | content: "保证各人修改的是同一套代码", | ||
144 | children: [ | ||
145 | { | ||
146 | type: "list_item", | ||
147 | depth: 6, | ||
148 | payload: { lines: [14, 15] }, | ||
149 | content: "每个人可以看到别人在做什么", | ||
150 | }, | ||
151 | { | ||
152 | type: "list_item", | ||
153 | depth: 6, | ||
154 | payload: { lines: [15, 16] }, | ||
155 | content: "管理员可以对用户权限进行管理", | ||
156 | }, | ||
157 | { | ||
158 | type: "list_item", | ||
159 | depth: 6, | ||
160 | payload: { lines: [16, 17] }, | ||
161 | content: | ||
162 | "中央服务器的单点故障,造成极严重的危害", | ||
163 | }, | ||
164 | ], | ||
165 | }, | ||
166 | ], | ||
167 | }, | ||
168 | { | ||
169 | type: "list_item", | ||
170 | depth: 4, | ||
171 | payload: { lines: [17, 18] }, | ||
172 | content: "分布式", | ||
173 | children: [ | ||
174 | { | ||
175 | type: "list_item", | ||
176 | depth: 5, | ||
177 | payload: { lines: [18, 19] }, | ||
178 | content: | ||
179 | "没中央服务器,各自为中心,各自进行版本控制", | ||
180 | }, | ||
181 | { | ||
182 | type: "list_item", | ||
183 | depth: 5, | ||
184 | payload: { lines: [19, 20] }, | ||
185 | content: "统一性由代码托管中心(远程库)储存", | ||
186 | children: [ | ||
187 | { | ||
188 | type: "list_item", | ||
189 | depth: 6, | ||
190 | payload: { lines: [20, 21] }, | ||
191 | content: "先克隆到本地再做版本控制", | ||
192 | }, | ||
193 | { | ||
194 | type: "list_item", | ||
195 | depth: 6, | ||
196 | payload: { lines: [21, 22] }, | ||
197 | content: | ||
198 | "写完push,保证远程库代码永远最新", | ||
199 | }, | ||
200 | { | ||
201 | type: "list_item", | ||
202 | depth: 6, | ||
203 | payload: { lines: [22, 23] }, | ||
204 | content: | ||
205 | "即使远程库挂掉,本地也可以继续工作,只不过无法上传", | ||
206 | }, | ||
207 | { | ||
208 | type: "list_item", | ||
209 | depth: 6, | ||
210 | payload: { lines: [23, 24] }, | ||
211 | content: "解决的问题", | ||
212 | }, | ||
213 | { | ||
214 | type: "list_item", | ||
215 | depth: 6, | ||
216 | payload: { lines: [24, 25] }, | ||
217 | content: "断网开发", | ||
218 | }, | ||
219 | { | ||
220 | type: "list_item", | ||
221 | depth: 6, | ||
222 | payload: { lines: [25, 26] }, | ||
223 | content: | ||
224 | "每个客户端都是整个完整项目(包含历史记录),更安全", | ||
225 | }, | ||
226 | ], | ||
227 | }, | ||
228 | ], | ||
229 | }, | ||
230 | { | ||
231 | type: "list_item", | ||
232 | depth: 4, | ||
233 | payload: { lines: [26, 27] }, | ||
234 | content: "Git历史(Linux开源,作版本控制)", | ||
235 | children: [ | ||
236 | { | ||
237 | type: "list_item", | ||
238 | depth: 5, | ||
239 | payload: { lines: [27, 28] }, | ||
240 | content: "Linus手动合并代码(1991起)", | ||
241 | }, | ||
242 | { | ||
243 | type: "list_item", | ||
244 | depth: 5, | ||
245 | payload: { lines: [28, 29] }, | ||
246 | content: | ||
247 | "2002,BitMover授权Linux社区免费试用BitKeeper", | ||
248 | }, | ||
249 | { | ||
250 | type: "list_item", | ||
251 | depth: 5, | ||
252 | payload: { lines: [29, 30] }, | ||
253 | content: "2005,Andrew违反协议破解了BitKeeper", | ||
254 | }, | ||
255 | { | ||
256 | type: "list_item", | ||
257 | depth: 5, | ||
258 | payload: { lines: [30, 31] }, | ||
259 | content: | ||
260 | "Linux两周开发了Git,一个月后Linux系统代码由Git管理", | ||
261 | }, | ||
262 | { | ||
263 | type: "list_item", | ||
264 | depth: 5, | ||
265 | payload: { lines: [31, 32] }, | ||
266 | content: "2008,GitHub上线,远程代码托管中心", | ||
267 | }, | ||
268 | ], | ||
269 | }, | ||
270 | ], | ||
271 | }, | ||
272 | ], | ||
273 | }, | ||
274 | { | ||
275 | type: "heading", | ||
276 | depth: 2, | ||
277 | payload: { lines: [32, 33] }, | ||
278 | content: "优点", | ||
279 | children: [ | ||
280 | { | ||
281 | type: "list_item", | ||
282 | depth: 3, | ||
283 | payload: { lines: [33, 34] }, | ||
284 | content: "快速高效处理从小到大各种项目", | ||
285 | }, | ||
286 | { | ||
287 | type: "list_item", | ||
288 | depth: 3, | ||
289 | payload: { lines: [34, 35] }, | ||
290 | content: "占地面积小", | ||
291 | }, | ||
292 | { | ||
293 | type: "list_item", | ||
294 | depth: 3, | ||
295 | payload: { lines: [35, 36] }, | ||
296 | content: "性能极快", | ||
297 | }, | ||
298 | { | ||
299 | type: "list_item", | ||
300 | depth: 3, | ||
301 | payload: { lines: [36, 37] }, | ||
302 | content: "廉价本地库", | ||
303 | }, | ||
304 | { | ||
305 | type: "list_item", | ||
306 | depth: 3, | ||
307 | payload: { lines: [37, 38] }, | ||
308 | content: "方便的暂存区", | ||
309 | }, | ||
310 | { | ||
311 | type: "list_item", | ||
312 | depth: 3, | ||
313 | payload: { lines: [38, 39] }, | ||
314 | content: "多个工作流分支,优于其他版本控制工具", | ||
315 | }, | ||
316 | ], | ||
317 | }, | ||
318 | { | ||
319 | type: "heading", | ||
320 | depth: 2, | ||
321 | payload: { lines: [39, 40] }, | ||
322 | content: '<a href="Git-scm.com">Git官网</a>介绍', | ||
323 | children: [ | ||
324 | { | ||
325 | type: "list_item", | ||
326 | depth: 3, | ||
327 | payload: { lines: [40, 41] }, | ||
328 | content: "Ererything is local", | ||
329 | }, | ||
330 | { | ||
331 | type: "list_item", | ||
332 | depth: 3, | ||
333 | payload: { lines: [41, 42] }, | ||
334 | content: "使用的公司", | ||
335 | children: [ | ||
336 | { | ||
337 | type: "list_item", | ||
338 | depth: 4, | ||
339 | payload: { lines: [42, 43] }, | ||
340 | content: "谷歌", | ||
341 | }, | ||
342 | { | ||
343 | type: "list_item", | ||
344 | depth: 4, | ||
345 | payload: { lines: [43, 44] }, | ||
346 | content: "脸书", | ||
347 | }, | ||
348 | { | ||
349 | type: "list_item", | ||
350 | depth: 4, | ||
351 | payload: { lines: [44, 45] }, | ||
352 | content: "微软", | ||
353 | }, | ||
354 | { | ||
355 | type: "list_item", | ||
356 | depth: 4, | ||
357 | payload: { lines: [45, 46] }, | ||
358 | content: "推特", | ||
359 | }, | ||
360 | { | ||
361 | type: "list_item", | ||
362 | depth: 4, | ||
363 | payload: { lines: [46, 47] }, | ||
364 | content: "安卓", | ||
365 | }, | ||
366 | { | ||
367 | type: "list_item", | ||
368 | depth: 4, | ||
369 | payload: { lines: [47, 48] }, | ||
370 | content: "linux", | ||
371 | }, | ||
372 | ], | ||
373 | }, | ||
374 | { | ||
375 | type: "list_item", | ||
376 | depth: 3, | ||
377 | payload: { lines: [48, 49] }, | ||
378 | content: "Git for windows 2.31.2", | ||
379 | }, | ||
380 | ], | ||
381 | }, | ||
382 | { | ||
383 | type: "heading", | ||
384 | depth: 2, | ||
385 | payload: { lines: [49, 50] }, | ||
386 | content: "Git工作机制", | ||
387 | children: [ | ||
388 | { | ||
389 | type: "list_item", | ||
390 | depth: 3, | ||
391 | payload: { lines: [50, 51] }, | ||
392 | content: "工作区", | ||
393 | children: [ | ||
394 | { | ||
395 | type: "list_item", | ||
396 | depth: 4, | ||
397 | payload: { lines: [51, 52] }, | ||
398 | content: "写代码", | ||
399 | }, | ||
400 | { | ||
401 | type: "list_item", | ||
402 | depth: 4, | ||
403 | payload: { lines: [52, 53] }, | ||
404 | content: "代码存放的磁盘的目录位置", | ||
405 | }, | ||
406 | ], | ||
407 | }, | ||
408 | { | ||
409 | type: "list_item", | ||
410 | depth: 3, | ||
411 | payload: { lines: [53, 54] }, | ||
412 | content: "暂存区", | ||
413 | children: [ | ||
414 | { | ||
415 | type: "list_item", | ||
416 | depth: 4, | ||
417 | payload: { lines: [54, 55] }, | ||
418 | content: "临时存储", | ||
419 | }, | ||
420 | { | ||
421 | type: "list_item", | ||
422 | depth: 4, | ||
423 | payload: { lines: [55, 56] }, | ||
424 | content: "添加暂存区<code>git add</code>", | ||
425 | }, | ||
426 | { | ||
427 | type: "list_item", | ||
428 | depth: 4, | ||
429 | payload: { lines: [56, 57] }, | ||
430 | content: "工作区删代码没有历史记录,暂存区也可以", | ||
431 | }, | ||
432 | ], | ||
433 | }, | ||
434 | { | ||
435 | type: "list_item", | ||
436 | depth: 3, | ||
437 | payload: { lines: [57, 58] }, | ||
438 | content: "本地库", | ||
439 | children: [ | ||
440 | { | ||
441 | type: "list_item", | ||
442 | depth: 4, | ||
443 | payload: { lines: [58, 59] }, | ||
444 | content: "生成历史版本", | ||
445 | }, | ||
446 | { | ||
447 | type: "list_item", | ||
448 | depth: 4, | ||
449 | payload: { lines: [59, 60] }, | ||
450 | content: "提交本地库<code>git commit</code>", | ||
451 | }, | ||
452 | { | ||
453 | type: "list_item", | ||
454 | depth: 4, | ||
455 | payload: { lines: [60, 61] }, | ||
456 | content: | ||
457 | "git的版本是基于上一版本的,不能单独删除历史版本", | ||
458 | }, | ||
459 | ], | ||
460 | }, | ||
461 | { | ||
462 | type: "list_item", | ||
463 | depth: 3, | ||
464 | payload: { lines: [61, 62] }, | ||
465 | content: "代码托管中心", | ||
466 | children: [ | ||
467 | { | ||
468 | type: "list_item", | ||
469 | depth: 4, | ||
470 | payload: { lines: [62, 63] }, | ||
471 | content: "基于网络服务的远程代码仓库(即远程库)", | ||
472 | }, | ||
473 | { | ||
474 | type: "list_item", | ||
475 | depth: 4, | ||
476 | payload: { lines: [63, 64] }, | ||
477 | content: "推送<code>git push</code>", | ||
478 | }, | ||
479 | { | ||
480 | type: "list_item", | ||
481 | depth: 4, | ||
482 | payload: { lines: [64, 65] }, | ||
483 | content: "GitLab/GitHub/Gitee(局域网)", | ||
484 | }, | ||
485 | ], | ||
486 | }, | ||
487 | ], | ||
488 | }, | ||
489 | { | ||
490 | type: "heading", | ||
491 | depth: 2, | ||
492 | payload: { lines: [65, 66] }, | ||
493 | content: "Git命令(基于开发案例)", | ||
494 | children: [ | ||
495 | { | ||
496 | type: "heading", | ||
497 | depth: 3, | ||
498 | payload: { lines: [66, 67] }, | ||
499 | content: "设置用户签名", | ||
500 | children: [ | ||
501 | { | ||
502 | type: "list_item", | ||
503 | depth: 4, | ||
504 | payload: { lines: [67, 68] }, | ||
505 | content: | ||
506 | "<code>git config --global user.name 用户名</code>", | ||
507 | }, | ||
508 | { | ||
509 | type: "list_item", | ||
510 | depth: 4, | ||
511 | payload: { lines: [68, 69] }, | ||
512 | content: | ||
513 | "<code>git config --global user.email 邮箱</code>", | ||
514 | }, | ||
515 | { | ||
516 | type: "list_item", | ||
517 | depth: 4, | ||
518 | payload: { lines: [69, 70] }, | ||
519 | content: | ||
520 | "打开<code>C:\\用户\\当前用户\\.gitconfig</code>查看是否已配置", | ||
521 | }, | ||
522 | { | ||
523 | type: "list_item", | ||
524 | depth: 4, | ||
525 | payload: { lines: [70, 71] }, | ||
526 | content: "签名的作用:", | ||
527 | children: [ | ||
528 | { | ||
529 | type: "list_item", | ||
530 | depth: 5, | ||
531 | payload: { lines: [71, 72] }, | ||
532 | content: "区分不同操作者身份", | ||
533 | }, | ||
534 | { | ||
535 | type: "list_item", | ||
536 | depth: 5, | ||
537 | payload: { lines: [72, 73] }, | ||
538 | content: | ||
539 | "此处设置的用户签名与GitHub/其他代码托管中心账号无任何关系", | ||
540 | }, | ||
541 | ], | ||
542 | }, | ||
543 | ], | ||
544 | }, | ||
545 | { | ||
546 | type: "heading", | ||
547 | depth: 3, | ||
548 | payload: { lines: [73, 74] }, | ||
549 | content: "本地库", | ||
550 | children: [ | ||
551 | { | ||
552 | type: "list_item", | ||
553 | depth: 4, | ||
554 | payload: { lines: [74, 75] }, | ||
555 | content: "初始化本地库", | ||
556 | children: [ | ||
557 | { | ||
558 | type: "list_item", | ||
559 | depth: 5, | ||
560 | payload: { lines: [75, 76] }, | ||
561 | content: | ||
562 | "打开需要跟踪作为本地库的文件夹,<code>git init</code>", | ||
563 | }, | ||
564 | ], | ||
565 | }, | ||
566 | { | ||
567 | type: "list_item", | ||
568 | depth: 4, | ||
569 | payload: { lines: [76, 77] }, | ||
570 | content: "查看本地库状态", | ||
571 | children: [ | ||
572 | { | ||
573 | type: "list_item", | ||
574 | depth: 5, | ||
575 | payload: { lines: [77, 78] }, | ||
576 | content: "<code>git status</code>,输出三行", | ||
577 | children: [ | ||
578 | { | ||
579 | type: "list_item", | ||
580 | depth: 6, | ||
581 | payload: { lines: [78, 79] }, | ||
582 | content: "当前所在分支", | ||
583 | }, | ||
584 | { | ||
585 | type: "list_item", | ||
586 | depth: 6, | ||
587 | payload: { lines: [79, 80] }, | ||
588 | content: "有无提交过", | ||
589 | }, | ||
590 | { | ||
591 | type: "list_item", | ||
592 | depth: 6, | ||
593 | payload: { lines: [80, 81] }, | ||
594 | content: "有无可提交文件", | ||
595 | }, | ||
596 | ], | ||
597 | }, | ||
598 | ], | ||
599 | }, | ||
600 | { | ||
601 | type: "list_item", | ||
602 | depth: 4, | ||
603 | payload: { lines: [81, 82] }, | ||
604 | content: "添加暂存区", | ||
605 | children: [ | ||
606 | { | ||
607 | type: "list_item", | ||
608 | depth: 5, | ||
609 | payload: { lines: [82, 83] }, | ||
610 | content: | ||
611 | "<code>git add <文件名></code>", | ||
612 | }, | ||
613 | { | ||
614 | type: "list_item", | ||
615 | depth: 5, | ||
616 | payload: { lines: [83, 84] }, | ||
617 | content: | ||
618 | "<code>git rm --cached <文件名></code>将文件从暂存区删除(工作区仍有)", | ||
619 | }, | ||
620 | ], | ||
621 | }, | ||
622 | { | ||
623 | type: "list_item", | ||
624 | depth: 4, | ||
625 | payload: { lines: [84, 85] }, | ||
626 | content: "提交本地库", | ||
627 | children: [ | ||
628 | { | ||
629 | type: "list_item", | ||
630 | depth: 5, | ||
631 | payload: { lines: [85, 86] }, | ||
632 | content: | ||
633 | "<code>git commit -m "日志信息"</code>", | ||
634 | }, | ||
635 | { | ||
636 | type: "list_item", | ||
637 | depth: 5, | ||
638 | payload: { lines: [86, 87] }, | ||
639 | content: | ||
640 | "<code>-m</code>为参数,跟日志信息,即使不加,也会要求写", | ||
641 | }, | ||
642 | { | ||
643 | type: "list_item", | ||
644 | depth: 5, | ||
645 | payload: { lines: [87, 88] }, | ||
646 | content: | ||
647 | "<code>git reflog</code>查看引用日志信息", | ||
648 | }, | ||
649 | { | ||
650 | type: "list_item", | ||
651 | depth: 5, | ||
652 | payload: { lines: [88, 89] }, | ||
653 | content: | ||
654 | "<code>git log</code>查看详细日志,除版本外,可以看到提交用户(原用户签名)、完整版本号", | ||
655 | }, | ||
656 | ], | ||
657 | }, | ||
658 | { | ||
659 | type: "list_item", | ||
660 | depth: 4, | ||
661 | payload: { lines: [89, 90] }, | ||
662 | content: "修改文件(略)", | ||
663 | }, | ||
664 | { | ||
665 | type: "list_item", | ||
666 | depth: 4, | ||
667 | payload: { lines: [90, 91] }, | ||
668 | content: "历史版本+版本穿梭", | ||
669 | children: [ | ||
670 | { | ||
671 | type: "list_item", | ||
672 | depth: 5, | ||
673 | payload: { lines: [91, 92] }, | ||
674 | content: | ||
675 | "<code>-m</code>为参数,跟日志信息,即使不加,也会要求写", | ||
676 | }, | ||
677 | { | ||
678 | type: "list_item", | ||
679 | depth: 5, | ||
680 | payload: { lines: [92, 93] }, | ||
681 | content: | ||
682 | "<code>git reflog</code>查看引用日志信息,可见精简的版本号、当前指针指向的分支", | ||
683 | }, | ||
684 | { | ||
685 | type: "list_item", | ||
686 | depth: 5, | ||
687 | payload: { lines: [93, 94] }, | ||
688 | content: | ||
689 | "<code>git log</code>查看详细日志,除版本外,可以看到提交用户(原用户签名)、完整版本号", | ||
690 | }, | ||
691 | { | ||
692 | type: "list_item", | ||
693 | depth: 5, | ||
694 | payload: { lines: [94, 95] }, | ||
695 | content: "版本穿梭", | ||
696 | children: [ | ||
697 | { | ||
698 | type: "list_item", | ||
699 | depth: 6, | ||
700 | payload: { lines: [95, 96] }, | ||
701 | content: "查看到版本号并赋值", | ||
702 | }, | ||
703 | { | ||
704 | type: "list_item", | ||
705 | depth: 6, | ||
706 | payload: { lines: [96, 97] }, | ||
707 | content: | ||
708 | "<code>git reset --hard <版本号></code>", | ||
709 | }, | ||
710 | { | ||
711 | type: "list_item", | ||
712 | depth: 6, | ||
713 | payload: { lines: [97, 98] }, | ||
714 | content: | ||
715 | "版本穿梭后可看到版本历史信息有标号(说不清,自己试)", | ||
716 | }, | ||
717 | { | ||
718 | type: "list_item", | ||
719 | depth: 6, | ||
720 | payload: { lines: [98, 99] }, | ||
721 | content: | ||
722 | "穿梭历史版本不会删除更新版本,仍然在工作树上", | ||
723 | }, | ||
724 | ], | ||
725 | }, | ||
726 | ], | ||
727 | }, | ||
728 | ], | ||
729 | }, | ||
730 | ], | ||
731 | }, | ||
732 | { | ||
733 | type: "heading", | ||
734 | depth: 2, | ||
735 | payload: { lines: [99, 100] }, | ||
736 | content: "Git分支", | ||
737 | children: [ | ||
738 | { | ||
739 | type: "list_item", | ||
740 | depth: 3, | ||
741 | payload: { lines: [100, 101] }, | ||
742 | content: "简介", | ||
743 | children: [ | ||
744 | { | ||
745 | type: "list_item", | ||
746 | depth: 4, | ||
747 | payload: { lines: [101, 102] }, | ||
748 | content: | ||
749 | "在版本控制过程中,同时推进多个任务,可各表一枝", | ||
750 | }, | ||
751 | { | ||
752 | type: "list_item", | ||
753 | depth: 4, | ||
754 | payload: { lines: [102, 103] }, | ||
755 | content: | ||
756 | "程序猿可以将自己的任务从开发主线分离出来,开发时不影响主线运行", | ||
757 | }, | ||
758 | { | ||
759 | type: "list_item", | ||
760 | depth: 4, | ||
761 | payload: { lines: [103, 104] }, | ||
762 | content: "分支的底层也是指针的引用", | ||
763 | }, | ||
764 | ], | ||
765 | }, | ||
766 | { | ||
767 | type: "list_item", | ||
768 | depth: 3, | ||
769 | payload: { lines: [104, 105] }, | ||
770 | content: "优点", | ||
771 | children: [ | ||
772 | { | ||
773 | type: "list_item", | ||
774 | depth: 4, | ||
775 | payload: { lines: [105, 106] }, | ||
776 | content: "同时并发推进多个功能开发,提高效率", | ||
777 | }, | ||
778 | { | ||
779 | type: "list_item", | ||
780 | depth: 4, | ||
781 | payload: { lines: [106, 107] }, | ||
782 | content: | ||
783 | "一个分支失败不会对其他分支有任何影响,单独重开即可", | ||
784 | }, | ||
785 | ], | ||
786 | }, | ||
787 | { | ||
788 | type: "list_item", | ||
789 | depth: 3, | ||
790 | payload: { lines: [107, 108] }, | ||
791 | content: "一般操作", | ||
792 | children: [ | ||
793 | { | ||
794 | type: "list_item", | ||
795 | depth: 4, | ||
796 | payload: { lines: [108, 109] }, | ||
797 | content: | ||
798 | "创建分支<code>git branch <创建的分支名></code>,本质为多创建一个指针", | ||
799 | }, | ||
800 | { | ||
801 | type: "list_item", | ||
802 | depth: 4, | ||
803 | payload: { lines: [109, 110] }, | ||
804 | content: "查看分支<code>git branch -v</code>", | ||
805 | }, | ||
806 | { | ||
807 | type: "list_item", | ||
808 | depth: 4, | ||
809 | payload: { lines: [110, 111] }, | ||
810 | content: | ||
811 | "切换分支<code>git checkout <目标分支名></code>,本质为HEAD指针所存顶部对象地址改动", | ||
812 | }, | ||
813 | ], | ||
814 | }, | ||
815 | { | ||
816 | type: "list_item", | ||
817 | depth: 3, | ||
818 | payload: { lines: [111, 112] }, | ||
819 | content: "分支合并", | ||
820 | children: [ | ||
821 | { | ||
822 | type: "list_item", | ||
823 | depth: 4, | ||
824 | payload: { lines: [112, 113] }, | ||
825 | content: | ||
826 | "将指定分支合并到当前分支<code>git merge <指定分支名></code>,为正常合并", | ||
827 | }, | ||
828 | { | ||
829 | type: "list_item", | ||
830 | depth: 4, | ||
831 | payload: { lines: [113, 114] }, | ||
832 | content: "代码冲突", | ||
833 | children: [ | ||
834 | { | ||
835 | type: "list_item", | ||
836 | depth: 5, | ||
837 | payload: { lines: [114, 115] }, | ||
838 | content: | ||
839 | "两个分支对同一文件同一位置有两套完全不同的修改,需要手动决定", | ||
840 | }, | ||
841 | { | ||
842 | type: "list_item", | ||
843 | depth: 5, | ||
844 | payload: { lines: [115, 116] }, | ||
845 | content: | ||
846 | "先<code>git merge <指定分支名></code>,报警,此时命令行标注的当前分支名显示正在合并但未完成,需要手动合并", | ||
847 | children: [ | ||
848 | { | ||
849 | type: "list_item", | ||
850 | depth: 6, | ||
851 | payload: { lines: [116, 117] }, | ||
852 | content: | ||
853 | "e.g.<code>player@Ubuntu > $ (master | MERGING)</code>", | ||
854 | }, | ||
855 | ], | ||
856 | }, | ||
857 | { | ||
858 | type: "list_item", | ||
859 | depth: 5, | ||
860 | payload: { lines: [117, 118] }, | ||
861 | content: | ||
862 | "此时再手动操作冲突的文件,将要保留的内容留下,其他冲突内容删除、特殊分割符号删除", | ||
863 | }, | ||
864 | { | ||
865 | type: "list_item", | ||
866 | depth: 5, | ||
867 | payload: { lines: [118, 119] }, | ||
868 | content: | ||
869 | "将此修改后的冲突文件重新添加暂存。提交本地库", | ||
870 | }, | ||
871 | { | ||
872 | type: "list_item", | ||
873 | depth: 5, | ||
874 | payload: { lines: [119, 120] }, | ||
875 | content: | ||
876 | "此时合并成功,命令行显示的当前分支名恢复正常", | ||
877 | }, | ||
878 | ], | ||
879 | }, | ||
880 | ], | ||
881 | }, | ||
882 | ], | ||
883 | }, | ||
884 | { | ||
885 | type: "heading", | ||
886 | depth: 2, | ||
887 | payload: { lines: [120, 121] }, | ||
888 | content: "团队协作机制", | ||
889 | children: [ | ||
890 | { | ||
891 | type: "list_item", | ||
892 | depth: 3, | ||
893 | payload: { lines: [121, 122] }, | ||
894 | content: | ||
895 | '注意参考<a href="https://www.bilibili.com/video/BV1vy4y1s7k6?p=19&spm_id_from=pageDriver&vd_source=0e7576154715d4dea629f3e001cde0ae">原视频</a>', | ||
896 | }, | ||
897 | { | ||
898 | type: "list_item", | ||
899 | depth: 3, | ||
900 | payload: { lines: [122, 123] }, | ||
901 | content: "代码托管中心(托A/B/C言之)", | ||
902 | }, | ||
903 | { | ||
904 | type: "list_item", | ||
905 | depth: 3, | ||
906 | payload: { lines: [123, 124] }, | ||
907 | content: "团队内协作", | ||
908 | children: [ | ||
909 | { | ||
910 | type: "list_item", | ||
911 | depth: 4, | ||
912 | payload: { lines: [124, 125] }, | ||
913 | content: | ||
914 | "A本地库push到a远程库,B则clone下来作为本地库修改", | ||
915 | }, | ||
916 | { | ||
917 | type: "list_item", | ||
918 | depth: 4, | ||
919 | payload: { lines: [125, 126] }, | ||
920 | content: "B修改后再push,A则pull下来查看最新的a", | ||
921 | }, | ||
922 | ], | ||
923 | }, | ||
924 | { | ||
925 | type: "list_item", | ||
926 | depth: 3, | ||
927 | payload: { lines: [126, 127] }, | ||
928 | content: "跨团队协作", | ||
929 | children: [ | ||
930 | { | ||
931 | type: "list_item", | ||
932 | depth: 4, | ||
933 | payload: { lines: [127, 128] }, | ||
934 | content: | ||
935 | "a远程库fork出b远程库,C经由本地库处理这个b远程库", | ||
936 | }, | ||
937 | { | ||
938 | type: "list_item", | ||
939 | depth: 4, | ||
940 | payload: { lines: [128, 129] }, | ||
941 | content: | ||
942 | "C提交拉取请求Pull Request,经对应人员审核后,与a远程库进行合并merge", | ||
943 | }, | ||
944 | ], | ||
945 | }, | ||
946 | ], | ||
947 | }, | ||
948 | ], | ||
949 | }, | ||
950 | { | ||
951 | type: "heading", | ||
952 | depth: 1, | ||
953 | payload: { lines: [129, 130] }, | ||
954 | content: "GitHub", | ||
955 | children: [ | ||
956 | { | ||
957 | type: "heading", | ||
958 | depth: 2, | ||
959 | payload: { lines: [130, 131] }, | ||
960 | content: "普通事项不多说,强调以下两点", | ||
961 | children: [ | ||
962 | { | ||
963 | type: "list_item", | ||
964 | depth: 3, | ||
965 | payload: { lines: [131, 132] }, | ||
966 | content: "仓库的Public/Private", | ||
967 | children: [ | ||
968 | { | ||
969 | type: "list_item", | ||
970 | depth: 4, | ||
971 | payload: { lines: [132, 133] }, | ||
972 | content: "Public的仓库,读权限完全放开", | ||
973 | }, | ||
974 | { | ||
975 | type: "list_item", | ||
976 | depth: 4, | ||
977 | payload: { lines: [133, 134] }, | ||
978 | content: | ||
979 | "Private的读权限只在团队内部,但不超过5人,否则收费(GitLab不香吗)", | ||
980 | }, | ||
981 | ], | ||
982 | }, | ||
983 | { | ||
984 | type: "list_item", | ||
985 | depth: 3, | ||
986 | payload: { lines: [134, 135] }, | ||
987 | content: "创建别名", | ||
988 | children: [ | ||
989 | { | ||
990 | type: "list_item", | ||
991 | depth: 4, | ||
992 | payload: { lines: [135, 136] }, | ||
993 | content: | ||
994 | "<code>git push <远程库链接> <分支名></code>,链接太长,在本地选择起别名", | ||
995 | children: [ | ||
996 | { | ||
997 | type: "list_item", | ||
998 | depth: 5, | ||
999 | payload: { lines: [136, 137] }, | ||
1000 | content: | ||
1001 | "新手直接<code>git push</code>/<code>git push origin main</code>/<code>git push origin</code>即可,省心省力,代码哪来的回哪去", | ||
1002 | }, | ||
1003 | ], | ||
1004 | }, | ||
1005 | { | ||
1006 | type: "list_item", | ||
1007 | depth: 4, | ||
1008 | payload: { lines: [137, 138] }, | ||
1009 | content: | ||
1010 | "<code>git remote add <别名> <远程地址></code>为指定地址创建别名", | ||
1011 | }, | ||
1012 | { | ||
1013 | type: "list_item", | ||
1014 | depth: 4, | ||
1015 | payload: { lines: [138, 139] }, | ||
1016 | content: | ||
1017 | "<code>git remote -v</code>查看1当前所有远程地址别名", | ||
1018 | children: [ | ||
1019 | { | ||
1020 | type: "list_item", | ||
1021 | depth: 5, | ||
1022 | payload: { lines: [139, 140] }, | ||
1023 | content: | ||
1024 | "一个别名既可以拉取(fetch)又可以push,所以查看时一个别名显示两条", | ||
1025 | }, | ||
1026 | ], | ||
1027 | }, | ||
1028 | ], | ||
1029 | }, | ||
1030 | ], | ||
1031 | }, | ||
1032 | { | ||
1033 | type: "heading", | ||
1034 | depth: 2, | ||
1035 | payload: { lines: [140, 141] }, | ||
1036 | content: "GitHub团队协作", | ||
1037 | children: [ | ||
1038 | { | ||
1039 | type: "list_item", | ||
1040 | depth: 3, | ||
1041 | payload: { lines: [141, 142] }, | ||
1042 | content: "机智如上,略,具体操作用到再说", | ||
1043 | }, | ||
1044 | ], | ||
1045 | }, | ||
1046 | { | ||
1047 | type: "heading", | ||
1048 | depth: 2, | ||
1049 | payload: { lines: [142, 143] }, | ||
1050 | content: "SSH免密登录GitHub", | ||
1051 | children: [ | ||
1052 | { | ||
1053 | type: "list_item", | ||
1054 | depth: 3, | ||
1055 | payload: { lines: [143, 144] }, | ||
1056 | content: | ||
1057 | "在远程仓库中点击<code>Code</code>(绿色),可见除了https链接还有一个ssh链接。", | ||
1058 | children: [ | ||
1059 | { | ||
1060 | type: "list_item", | ||
1061 | depth: 4, | ||
1062 | payload: { lines: [144, 145] }, | ||
1063 | content: "使用时需要本地git已经通过ssh连接github", | ||
1064 | }, | ||
1065 | ], | ||
1066 | }, | ||
1067 | { | ||
1068 | type: "list_item", | ||
1069 | depth: 3, | ||
1070 | payload: { lines: [145, 146] }, | ||
1071 | content: | ||
1072 | "在<code>git clone <链接></code>或<code>git push <链接></code>时,除https链接即网址外,也可使用仓库ssh,其他操作一切正常", | ||
1073 | }, | ||
1074 | ], | ||
1075 | }, | ||
1076 | ], | ||
1077 | }, | ||
1078 | { | ||
1079 | type: "heading", | ||
1080 | depth: 1, | ||
1081 | payload: { lines: [146, 147] }, | ||
1082 | content: "Gitee码云", | ||
1083 | children: [ | ||
1084 | { | ||
1085 | type: "bullet_list", | ||
1086 | depth: 2, | ||
1087 | payload: { lines: [147, 149] }, | ||
1088 | content: "", | ||
1089 | children: [ | ||
1090 | { | ||
1091 | type: "list_item", | ||
1092 | depth: 3, | ||
1093 | payload: { lines: [147, 148] }, | ||
1094 | content: "国内代码托管网站,开源中国推出,中文网站", | ||
1095 | }, | ||
1096 | { | ||
1097 | type: "list_item", | ||
1098 | depth: 3, | ||
1099 | payload: { lines: [148, 149] }, | ||
1100 | content: "完全仿照GitHub开发,日常使用基本一致,不赘", | ||
1101 | }, | ||
1102 | ], | ||
1103 | }, | ||
1104 | { | ||
1105 | type: "heading", | ||
1106 | depth: 2, | ||
1107 | payload: { lines: [149, 150] }, | ||
1108 | content: "连接GitHub进行代码复制/迁移", | ||
1109 | children: [ | ||
1110 | { | ||
1111 | type: "list_item", | ||
1112 | depth: 3, | ||
1113 | payload: { lines: [150, 151] }, | ||
1114 | content: | ||
1115 | "新建仓库,不输入仓库名,在下方选择“导入已有仓库”,输入GitHub项目的链接(必须为https协议)", | ||
1116 | }, | ||
1117 | { | ||
1118 | type: "list_item", | ||
1119 | depth: 3, | ||
1120 | payload: { lines: [151, 152] }, | ||
1121 | content: "若输入后弹出绿框,极为正常,点击创建", | ||
1122 | }, | ||
1123 | { | ||
1124 | type: "list_item", | ||
1125 | depth: 3, | ||
1126 | payload: { lines: [152, 153] }, | ||
1127 | content: | ||
1128 | "仓库更新,进入gitee仓库后,点击仓库名后更新按钮,即可自动更新", | ||
1129 | }, | ||
1130 | ], | ||
1131 | }, | ||
1132 | ], | ||
1133 | }, | ||
1134 | { | ||
1135 | type: "heading", | ||
1136 | depth: 1, | ||
1137 | payload: { lines: [153, 154] }, | ||
1138 | content: "GitLab", | ||
1139 | children: [ | ||
1140 | { | ||
1141 | type: "bullet_list", | ||
1142 | depth: 2, | ||
1143 | payload: { lines: [154, 156] }, | ||
1144 | content: "", | ||
1145 | children: [ | ||
1146 | { | ||
1147 | type: "list_item", | ||
1148 | depth: 3, | ||
1149 | payload: { lines: [154, 155] }, | ||
1150 | content: | ||
1151 | "开源的自建代码托管平台,局域网代码托管中心(在一定范围内共享,外部禁止)", | ||
1152 | }, | ||
1153 | { | ||
1154 | type: "list_item", | ||
1155 | depth: 3, | ||
1156 | payload: { lines: [155, 156] }, | ||
1157 | content: | ||
1158 | '<a href="https://about.gitlab.com">官网地址</a>、<a href="https://about.gitlab.com/installation">安装说明</a>', | ||
1159 | }, | ||
1160 | ], | ||
1161 | }, | ||
1162 | { | ||
1163 | type: "heading", | ||
1164 | depth: 2, | ||
1165 | payload: { lines: [156, 157] }, | ||
1166 | content: "服务器的搭建与部署", | ||
1167 | children: [ | ||
1168 | { | ||
1169 | type: "list_item", | ||
1170 | depth: 3, | ||
1171 | payload: { lines: [157, 158] }, | ||
1172 | content: "服务器准备", | ||
1173 | children: [ | ||
1174 | { | ||
1175 | type: "list_item", | ||
1176 | depth: 4, | ||
1177 | payload: { lines: [158, 159] }, | ||
1178 | content: | ||
1179 | "下载时查看各系统服务器要求,安装过程省略", | ||
1180 | }, | ||
1181 | ], | ||
1182 | }, | ||
1183 | { | ||
1184 | type: "list_item", | ||
1185 | depth: 3, | ||
1186 | payload: { lines: [159, 160] }, | ||
1187 | content: "其余安装和使用过程省略,用到再说", | ||
1188 | }, | ||
1189 | ], | ||
1190 | }, | ||
1191 | ], | ||
1192 | }, | ||
1193 | ], | ||
1194 | }, | ||
1195 | {} | ||
1196 | ); | ||
1197 | </script> | ||
1198 | <p class="time">2023.2</p> | ||
1199 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment4works.js"></script> | ||
27 | </div> | 1200 | </div> |
28 | </div> | 1201 | </div> |
29 | <svg id="mindmap"></svg> | ||
30 | <script src="https://cdn.jsdelivr.net/npm/d3@6.7.0"></script> | ||
31 | <script src="https://cdn.jsdelivr.net/npm/markmap-view@0.14.3"></script> | ||
32 | <script src="https://cdn.jsdelivr.net/npm/markmap-toolbar@0.14.3/dist/index.umd.min.js"></script> | ||
33 | <script>((getMarkmap, getOptions, root, jsonOptions) => { | ||
34 | const markmap = getMarkmap(); | ||
35 | window.mm = markmap.Markmap.create('svg#mindmap', (getOptions || markmap.deriveOptions)(jsonOptions), root); | ||
36 | })(() => window.markmap, null, { "type": "heading", "depth": 0, "payload": { "lines": [0, 1] }, "content": "Git", "children": [{ "type": "bullet_list", "depth": 1, "payload": { "lines": [1, 2] }, "content": "", "children": [{ "type": "list_item", "depth": 2, "payload": { "lines": [1, 2] }, "content": "课程目标:5h熟练掌握以下内容" }] }, { "type": "heading", "depth": 1, "payload": { "lines": [2, 3] }, "content": "Git介绍", "children": [{ "type": "heading", "depth": 2, "payload": { "lines": [3, 4] }, "content": "免费的开源分布式VCS", "children": [{ "type": "heading", "depth": 3, "payload": { "lines": [4, 5] }, "content": "版本控制", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [5, 6] }, "content": "记录文件内容变化" }, { "type": "list_item", "depth": 4, "payload": { "lines": [6, 7] }, "content": "查阅特定历史版本" }, { "type": "list_item", "depth": 4, "payload": { "lines": [7, 8] }, "content": "记录文件修改的历史记录、查看历史版本、作版本切换" }, { "type": "list_item", "depth": 4, "payload": { "lines": [8, 9] }, "content": "个人开发过渡到团队协作的需求" }] }, { "type": "heading", "depth": 3, "payload": { "lines": [9, 10] }, "content": "分布式VCS VS 集中式VCS", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [10, 11] }, "content": "集中的版本控制工具", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [11, 12] }, "content": "CVS/SVN" }, { "type": "list_item", "depth": 5, "payload": { "lines": [12, 13] }, "content": "中央服务器" }, { "type": "list_item", "depth": 5, "payload": { "lines": [13, 14] }, "content": "保证各人修改的是同一套代码", "children": [{ "type": "list_item", "depth": 6, "payload": { "lines": [14, 15] }, "content": "每个人可以看到别人在做什么" }, { "type": "list_item", "depth": 6, "payload": { "lines": [15, 16] }, "content": "管理员可以对用户权限进行管理" }, { "type": "list_item", "depth": 6, "payload": { "lines": [16, 17] }, "content": "中央服务器的单点故障,造成极严重的危害" }] }] }, { "type": "list_item", "depth": 4, "payload": { "lines": [17, 18] }, "content": "分布式", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [18, 19] }, "content": "没中央服务器,各自为中心,各自进行版本控制" }, { "type": "list_item", "depth": 5, "payload": { "lines": [19, 20] }, "content": "统一性由代码托管中心(远程库)储存", "children": [{ "type": "list_item", "depth": 6, "payload": { "lines": [20, 21] }, "content": "先克隆到本地再做版本控制" }, { "type": "list_item", "depth": 6, "payload": { "lines": [21, 22] }, "content": "写完push,保证远程库代码永远最新" }, { "type": "list_item", "depth": 6, "payload": { "lines": [22, 23] }, "content": "即使远程库挂掉,本地也可以继续工作,只不过无法上传" }, { "type": "list_item", "depth": 6, "payload": { "lines": [23, 24] }, "content": "解决的问题" }, { "type": "list_item", "depth": 6, "payload": { "lines": [24, 25] }, "content": "断网开发" }, { "type": "list_item", "depth": 6, "payload": { "lines": [25, 26] }, "content": "每个客户端都是整个完整项目(包含历史记录),更安全" }] }] }, { "type": "list_item", "depth": 4, "payload": { "lines": [26, 27] }, "content": "Git历史(Linux开源,作版本控制)", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [27, 28] }, "content": "Linus手动合并代码(1991起)" }, { "type": "list_item", "depth": 5, "payload": { "lines": [28, 29] }, "content": "2002,BitMover授权Linux社区免费试用BitKeeper" }, { "type": "list_item", "depth": 5, "payload": { "lines": [29, 30] }, "content": "2005,Andrew违反协议破解了BitKeeper" }, { "type": "list_item", "depth": 5, "payload": { "lines": [30, 31] }, "content": "Linux两周开发了Git,一个月后Linux系统代码由Git管理" }, { "type": "list_item", "depth": 5, "payload": { "lines": [31, 32] }, "content": "2008,GitHub上线,远程代码托管中心" }] }] }] }, { "type": "heading", "depth": 2, "payload": { "lines": [32, 33] }, "content": "优点", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [33, 34] }, "content": "快速高效处理从小到大各种项目" }, { "type": "list_item", "depth": 3, "payload": { "lines": [34, 35] }, "content": "占地面积小" }, { "type": "list_item", "depth": 3, "payload": { "lines": [35, 36] }, "content": "性能极快" }, { "type": "list_item", "depth": 3, "payload": { "lines": [36, 37] }, "content": "廉价本地库" }, { "type": "list_item", "depth": 3, "payload": { "lines": [37, 38] }, "content": "方便的暂存区" }, { "type": "list_item", "depth": 3, "payload": { "lines": [38, 39] }, "content": "多个工作流分支,优于其他版本控制工具" }] }, { "type": "heading", "depth": 2, "payload": { "lines": [39, 40] }, "content": "<a href=\"Git-scm.com\">Git官网</a>介绍", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [40, 41] }, "content": "Ererything is local" }, { "type": "list_item", "depth": 3, "payload": { "lines": [41, 42] }, "content": "使用的公司", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [42, 43] }, "content": "谷歌" }, { "type": "list_item", "depth": 4, "payload": { "lines": [43, 44] }, "content": "脸书" }, { "type": "list_item", "depth": 4, "payload": { "lines": [44, 45] }, "content": "微软" }, { "type": "list_item", "depth": 4, "payload": { "lines": [45, 46] }, "content": "推特" }, { "type": "list_item", "depth": 4, "payload": { "lines": [46, 47] }, "content": "安卓" }, { "type": "list_item", "depth": 4, "payload": { "lines": [47, 48] }, "content": "linux" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [48, 49] }, "content": "Git for windows 2.31.2" }] }, { "type": "heading", "depth": 2, "payload": { "lines": [49, 50] }, "content": "Git工作机制", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [50, 51] }, "content": "工作区", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [51, 52] }, "content": "写代码" }, { "type": "list_item", "depth": 4, "payload": { "lines": [52, 53] }, "content": "代码存放的磁盘的目录位置" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [53, 54] }, "content": "暂存区", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [54, 55] }, "content": "临时存储" }, { "type": "list_item", "depth": 4, "payload": { "lines": [55, 56] }, "content": "添加暂存区<code>git add</code>" }, { "type": "list_item", "depth": 4, "payload": { "lines": [56, 57] }, "content": "工作区删代码没有历史记录,暂存区也可以" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [57, 58] }, "content": "本地库", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [58, 59] }, "content": "生成历史版本" }, { "type": "list_item", "depth": 4, "payload": { "lines": [59, 60] }, "content": "提交本地库<code>git commit</code>" }, { "type": "list_item", "depth": 4, "payload": { "lines": [60, 61] }, "content": "git的版本是基于上一版本的,不能单独删除历史版本" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [61, 62] }, "content": "代码托管中心", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [62, 63] }, "content": "基于网络服务的远程代码仓库(即远程库)" }, { "type": "list_item", "depth": 4, "payload": { "lines": [63, 64] }, "content": "推送<code>git push</code>" }, { "type": "list_item", "depth": 4, "payload": { "lines": [64, 65] }, "content": "GitLab/GitHub/Gitee(局域网)" }] }] }, { "type": "heading", "depth": 2, "payload": { "lines": [65, 66] }, "content": "Git命令(基于开发案例)", "children": [{ "type": "heading", "depth": 3, "payload": { "lines": [66, 67] }, "content": "设置用户签名", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [67, 68] }, "content": "<code>git config --global user.name 用户名</code>" }, { "type": "list_item", "depth": 4, "payload": { "lines": [68, 69] }, "content": "<code>git config --global user.email 邮箱</code>" }, { "type": "list_item", "depth": 4, "payload": { "lines": [69, 70] }, "content": "打开<code>C:\\用户\\当前用户\\.gitconfig</code>查看是否已配置" }, { "type": "list_item", "depth": 4, "payload": { "lines": [70, 71] }, "content": "签名的作用:", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [71, 72] }, "content": "区分不同操作者身份" }, { "type": "list_item", "depth": 5, "payload": { "lines": [72, 73] }, "content": "此处设置的用户签名与GitHub/其他代码托管中心账号无任何关系" }] }] }, { "type": "heading", "depth": 3, "payload": { "lines": [73, 74] }, "content": "本地库", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [74, 75] }, "content": "初始化本地库", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [75, 76] }, "content": "打开需要跟踪作为本地库的文件夹,<code>git init</code>" }] }, { "type": "list_item", "depth": 4, "payload": { "lines": [76, 77] }, "content": "查看本地库状态", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [77, 78] }, "content": "<code>git status</code>,输出三行", "children": [{ "type": "list_item", "depth": 6, "payload": { "lines": [78, 79] }, "content": "当前所在分支" }, { "type": "list_item", "depth": 6, "payload": { "lines": [79, 80] }, "content": "有无提交过" }, { "type": "list_item", "depth": 6, "payload": { "lines": [80, 81] }, "content": "有无可提交文件" }] }] }, { "type": "list_item", "depth": 4, "payload": { "lines": [81, 82] }, "content": "添加暂存区", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [82, 83] }, "content": "<code>git add <文件名></code>" }, { "type": "list_item", "depth": 5, "payload": { "lines": [83, 84] }, "content": "<code>git rm --cached <文件名></code>将文件从暂存区删除(工作区仍有)" }] }, { "type": "list_item", "depth": 4, "payload": { "lines": [84, 85] }, "content": "提交本地库", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [85, 86] }, "content": "<code>git commit -m "日志信息"</code>" }, { "type": "list_item", "depth": 5, "payload": { "lines": [86, 87] }, "content": "<code>-m</code>为参数,跟日志信息,即使不加,也会要求写" }, { "type": "list_item", "depth": 5, "payload": { "lines": [87, 88] }, "content": "<code>git reflog</code>查看引用日志信息" }, { "type": "list_item", "depth": 5, "payload": { "lines": [88, 89] }, "content": "<code>git log</code>查看详细日志,除版本外,可以看到提交用户(原用户签名)、完整版本号" }] }, { "type": "list_item", "depth": 4, "payload": { "lines": [89, 90] }, "content": "修改文件(略)" }, { "type": "list_item", "depth": 4, "payload": { "lines": [90, 91] }, "content": "历史版本+版本穿梭", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [91, 92] }, "content": "<code>-m</code>为参数,跟日志信息,即使不加,也会要求写" }, { "type": "list_item", "depth": 5, "payload": { "lines": [92, 93] }, "content": "<code>git reflog</code>查看引用日志信息,可见精简的版本号、当前指针指向的分支" }, { "type": "list_item", "depth": 5, "payload": { "lines": [93, 94] }, "content": "<code>git log</code>查看详细日志,除版本外,可以看到提交用户(原用户签名)、完整版本号" }, { "type": "list_item", "depth": 5, "payload": { "lines": [94, 95] }, "content": "版本穿梭", "children": [{ "type": "list_item", "depth": 6, "payload": { "lines": [95, 96] }, "content": "查看到版本号并赋值" }, { "type": "list_item", "depth": 6, "payload": { "lines": [96, 97] }, "content": "<code>git reset --hard <版本号></code>" }, { "type": "list_item", "depth": 6, "payload": { "lines": [97, 98] }, "content": "版本穿梭后可看到版本历史信息有标号(说不清,自己试)" }, { "type": "list_item", "depth": 6, "payload": { "lines": [98, 99] }, "content": "穿梭历史版本不会删除更新版本,仍然在工作树上" }] }] }] }] }, { "type": "heading", "depth": 2, "payload": { "lines": [99, 100] }, "content": "Git分支", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [100, 101] }, "content": "简介", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [101, 102] }, "content": "在版本控制过程中,同时推进多个任务,可各表一枝" }, { "type": "list_item", "depth": 4, "payload": { "lines": [102, 103] }, "content": "程序猿可以将自己的任务从开发主线分离出来,开发时不影响主线运行" }, { "type": "list_item", "depth": 4, "payload": { "lines": [103, 104] }, "content": "分支的底层也是指针的引用" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [104, 105] }, "content": "优点", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [105, 106] }, "content": "同时并发推进多个功能开发,提高效率" }, { "type": "list_item", "depth": 4, "payload": { "lines": [106, 107] }, "content": "一个分支失败不会对其他分支有任何影响,单独重开即可" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [107, 108] }, "content": "一般操作", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [108, 109] }, "content": "创建分支<code>git branch <创建的分支名></code>,本质为多创建一个指针" }, { "type": "list_item", "depth": 4, "payload": { "lines": [109, 110] }, "content": "查看分支<code>git branch -v</code>" }, { "type": "list_item", "depth": 4, "payload": { "lines": [110, 111] }, "content": "切换分支<code>git checkout <目标分支名></code>,本质为HEAD指针所存顶部对象地址改动" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [111, 112] }, "content": "分支合并", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [112, 113] }, "content": "将指定分支合并到当前分支<code>git merge <指定分支名></code>,为正常合并" }, { "type": "list_item", "depth": 4, "payload": { "lines": [113, 114] }, "content": "代码冲突", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [114, 115] }, "content": "两个分支对同一文件同一位置有两套完全不同的修改,需要手动决定" }, { "type": "list_item", "depth": 5, "payload": { "lines": [115, 116] }, "content": "先<code>git merge <指定分支名></code>,报警,此时命令行标注的当前分支名显示正在合并但未完成,需要手动合并", "children": [{ "type": "list_item", "depth": 6, "payload": { "lines": [116, 117] }, "content": "e.g.<code>player@Ubuntu > $ (master | MERGING)</code>" }] }, { "type": "list_item", "depth": 5, "payload": { "lines": [117, 118] }, "content": "此时再手动操作冲突的文件,将要保留的内容留下,其他冲突内容删除、特殊分割符号删除" }, { "type": "list_item", "depth": 5, "payload": { "lines": [118, 119] }, "content": "将此修改后的冲突文件重新添加暂存。提交本地库" }, { "type": "list_item", "depth": 5, "payload": { "lines": [119, 120] }, "content": "此时合并成功,命令行显示的当前分支名恢复正常" }] }] }] }, { "type": "heading", "depth": 2, "payload": { "lines": [120, 121] }, "content": "团队协作机制", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [121, 122] }, "content": "注意参考<a href=\"https://www.bilibili.com/video/BV1vy4y1s7k6?p=19&spm_id_from=pageDriver&vd_source=0e7576154715d4dea629f3e001cde0ae\">原视频</a>" }, { "type": "list_item", "depth": 3, "payload": { "lines": [122, 123] }, "content": "代码托管中心(托A/B/C言之)" }, { "type": "list_item", "depth": 3, "payload": { "lines": [123, 124] }, "content": "团队内协作", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [124, 125] }, "content": "A本地库push到a远程库,B则clone下来作为本地库修改" }, { "type": "list_item", "depth": 4, "payload": { "lines": [125, 126] }, "content": "B修改后再push,A则pull下来查看最新的a" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [126, 127] }, "content": "跨团队协作", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [127, 128] }, "content": "a远程库fork出b远程库,C经由本地库处理这个b远程库" }, { "type": "list_item", "depth": 4, "payload": { "lines": [128, 129] }, "content": "C提交拉取请求Pull Request,经对应人员审核后,与a远程库进行合并merge" }] }] }] }, { "type": "heading", "depth": 1, "payload": { "lines": [129, 130] }, "content": "GitHub", "children": [{ "type": "heading", "depth": 2, "payload": { "lines": [130, 131] }, "content": "普通事项不多说,强调以下两点", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [131, 132] }, "content": "仓库的Public/Private", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [132, 133] }, "content": "Public的仓库,读权限完全放开" }, { "type": "list_item", "depth": 4, "payload": { "lines": [133, 134] }, "content": "Private的读权限只在团队内部,但不超过5人,否则收费(GitLab不香吗)" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [134, 135] }, "content": "创建别名", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [135, 136] }, "content": "<code>git push <远程库链接> <分支名></code>,链接太长,在本地选择起别名", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [136, 137] }, "content": "新手直接<code>git push</code>/<code>git push origin main</code>/<code>git push origin</code>即可,省心省力,代码哪来的回哪去" }] }, { "type": "list_item", "depth": 4, "payload": { "lines": [137, 138] }, "content": "<code>git remote add <别名> <远程地址></code>为指定地址创建别名" }, { "type": "list_item", "depth": 4, "payload": { "lines": [138, 139] }, "content": "<code>git remote -v</code>查看1当前所有远程地址别名", "children": [{ "type": "list_item", "depth": 5, "payload": { "lines": [139, 140] }, "content": "一个别名既可以拉取(fetch)又可以push,所以查看时一个别名显示两条" }] }] }] }, { "type": "heading", "depth": 2, "payload": { "lines": [140, 141] }, "content": "GitHub团队协作", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [141, 142] }, "content": "机智如上,略,具体操作用到再说" }] }, { "type": "heading", "depth": 2, "payload": { "lines": [142, 143] }, "content": "SSH免密登录GitHub", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [143, 144] }, "content": "在远程仓库中点击<code>Code</code>(绿色),可见除了https链接还有一个ssh链接。", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [144, 145] }, "content": "使用时需要本地git已经通过ssh连接github" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [145, 146] }, "content": "在<code>git clone <链接></code>或<code>git push <链接></code>时,除https链接即网址外,也可使用仓库ssh,其他操作一切正常" }] }] }, { "type": "heading", "depth": 1, "payload": { "lines": [146, 147] }, "content": "Gitee码云", "children": [{ "type": "bullet_list", "depth": 2, "payload": { "lines": [147, 149] }, "content": "", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [147, 148] }, "content": "国内代码托管网站,开源中国推出,中文网站" }, { "type": "list_item", "depth": 3, "payload": { "lines": [148, 149] }, "content": "完全仿照GitHub开发,日常使用基本一致,不赘" }] }, { "type": "heading", "depth": 2, "payload": { "lines": [149, 150] }, "content": "连接GitHub进行代码复制/迁移", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [150, 151] }, "content": "新建仓库,不输入仓库名,在下方选择“导入已有仓库”,输入GitHub项目的链接(必须为https协议)" }, { "type": "list_item", "depth": 3, "payload": { "lines": [151, 152] }, "content": "若输入后弹出绿框,极为正常,点击创建" }, { "type": "list_item", "depth": 3, "payload": { "lines": [152, 153] }, "content": "仓库更新,进入gitee仓库后,点击仓库名后更新按钮,即可自动更新" }] }] }, { "type": "heading", "depth": 1, "payload": { "lines": [153, 154] }, "content": "GitLab", "children": [{ "type": "bullet_list", "depth": 2, "payload": { "lines": [154, 156] }, "content": "", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [154, 155] }, "content": "开源的自建代码托管平台,局域网代码托管中心(在一定范围内共享,外部禁止)" }, { "type": "list_item", "depth": 3, "payload": { "lines": [155, 156] }, "content": "<a href=\"https://about.gitlab.com\">官网地址</a>、<a href=\"https://about.gitlab.com/installation\">安装说明</a>" }] }, { "type": "heading", "depth": 2, "payload": { "lines": [156, 157] }, "content": "服务器的搭建与部署", "children": [{ "type": "list_item", "depth": 3, "payload": { "lines": [157, 158] }, "content": "服务器准备", "children": [{ "type": "list_item", "depth": 4, "payload": { "lines": [158, 159] }, "content": "下载时查看各系统服务器要求,安装过程省略" }] }, { "type": "list_item", "depth": 3, "payload": { "lines": [159, 160] }, "content": "其余安装和使用过程省略,用到再说" }] }] }] }, {})</script> | ||
37 | </body> | 1202 | </body> |
38 | 1203 | ||
39 | </html> \ No newline at end of file | 1204 | </html> \ No newline at end of file |
diff --git a/courseNotes/git/git_tutor.html b/courseNotes/git/git_tutor.html index 716545b..12b2455 100644 --- a/courseNotes/git/git_tutor.html +++ b/courseNotes/git/git_tutor.html | |||
@@ -935,15 +935,36 @@ | |||
935 | <p><span>根据以上说明,现在可以对Git仓库加以解释:仓库是数据对象和引用。</span></p> | 935 | <p><span>根据以上说明,现在可以对Git仓库加以解释:仓库是数据对象和引用。</span></p> |
936 | <h1 id='部分说明课后习题'><span>部分说明课后习题</span></h1> | 936 | <h1 id='部分说明课后习题'><span>部分说明课后习题</span></h1> |
937 | <ul> | 937 | <ul> |
938 | <li><p><span>阅读</span><a href="https://git-scm.com/book/en/v2"><span>Pro Git</span></a><span>和/或</span><a | 938 | <li> |
939 | href="https://learngitbranching.js.org/?locale=zh_CN"><span>Learning Git Branching</span></a></p></li> | 939 | <p><span>阅读</span><a href="https://git-scm.com/book/en/v2"><span>Pro Git</span></a><span>和/或</span><a |
940 | <li><p><span>略。</span></p></li> | 940 | href="https://learngitbranching.js.org/?locale=zh_CN"><span>Learning Git Branching</span></a></p> |
941 | <li><p><span>略。</span></p></li> | 941 | </li> |
942 | <li><p><span>如下:</span></p><ul><li><code>git stash</code><span>将暂存区(尚未提交)全部内容放入堆栈,可用以解决代码版本冲突(如,本地</span><code>git stash</code><span>后,重新拉取远程库代码,然后</span><code>git stash pop</code><span>将存入的内容出栈放回)。</span></li><li><code>git log --all --oneline</code><span>展示所有历史版本的引用ref和对应日志信息。</span></li></ul></li> | 942 | <li> |
943 | <li><p><span>略</span></p></li> | 943 | <p><span>略。</span></p> |
944 | <li><p><span>略</span></p></li> | 944 | </li> |
945 | <li><p><span>略</span></p></li> | 945 | <li> |
946 | <p><span>略。</span></p> | ||
947 | </li> | ||
948 | <li> | ||
949 | <p><span>如下:</span></p> | ||
950 | <ul> | ||
951 | <li><code>git stash</code><span>将暂存区(尚未提交)全部内容放入堆栈,可用以解决代码版本冲突(如,本地</span><code>git stash</code><span>后,重新拉取远程库代码,然后</span><code>git stash pop</code><span>将存入的内容出栈放回)。</span> | ||
952 | </li> | ||
953 | <li><code>git log --all --oneline</code><span>展示所有历史版本的引用ref和对应日志信息。</span></li> | ||
954 | </ul> | ||
955 | </li> | ||
956 | <li> | ||
957 | <p><span>略</span></p> | ||
958 | </li> | ||
959 | <li> | ||
960 | <p><span>略</span></p> | ||
961 | </li> | ||
962 | <li> | ||
963 | <p><span>略</span></p> | ||
964 | </li> | ||
946 | </ul> | 965 | </ul> |
966 | <p class="time">2023.2</p> | ||
967 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment4works.js"></script> | ||
947 | </div> | 968 | </div> |
948 | </div> | 969 | </div> |
949 | </body> | 970 | </body> |
diff --git a/courseNotes/mathematical_logic.html b/courseNotes/mathematical_logic.html index 4a73e96..96942d8 100644 --- a/courseNotes/mathematical_logic.html +++ b/courseNotes/mathematical_logic.html | |||
@@ -2225,7 +2225,8 @@ | |||
2225 | ); | 2225 | ); |
2226 | </script> | 2226 | </script> |
2227 | </div> | 2227 | </div> |
2228 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | 2228 | <p class="time">2022.12</p> |
2229 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment4works.js"></script> | ||
2229 | </div> | 2230 | </div> |
2230 | </div> | 2231 | </div> |
2231 | </body> | 2232 | </body> |
diff --git a/courseNotes/parallel.html b/courseNotes/parallel.html index 5991afc..163bd24 100644 --- a/courseNotes/parallel.html +++ b/courseNotes/parallel.html | |||
@@ -7,6 +7,7 @@ | |||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
8 | <title>并行计算大法好</title> | 8 | <title>并行计算大法好</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | ||
10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
11 | <script src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> | 12 | <script src="https://www.qin-juan-ge-zhu.top/common/js/myhighlight.js"></script> |
12 | <script type="text/javascript" async | 13 | <script type="text/javascript" async |
@@ -1858,7 +1859,7 @@ int main() | |||
1858 | return 0; | 1859 | return 0; |
1859 | }</code></pre> | 1860 | }</code></pre> |
1860 | <p>CUDA 后续的理论讲解较多,恕不能一一列举于此。直接看 PPT 罢。</p> | 1861 | <p>CUDA 后续的理论讲解较多,恕不能一一列举于此。直接看 PPT 罢。</p> |
1861 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | 1862 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment4works.js"></script> |
1862 | </div> | 1863 | </div> |
1863 | </div> | 1864 | </div> |
1864 | </body> | 1865 | </body> |
@@ -13,7 +13,6 @@ | |||
13 | <body class="typora-export os-windows" style="display:flex;"> | 13 | <body class="typora-export os-windows" style="display:flex;"> |
14 | <div class="background" style="font-size: medium;"> | 14 | <div class="background" style="font-size: medium;"> |
15 | <div class="box"> | 15 | <div class="box"> |
16 | |||
17 | <!-- 欢迎来到 --> | 16 | <!-- 欢迎来到 --> |
18 | <svg width="56.824" height="61.208" viewBox="0 0 56.824 63.208" xmlns="http://www.w3.org/2000/svg" | 17 | <svg width="56.824" height="61.208" viewBox="0 0 56.824 63.208" xmlns="http://www.w3.org/2000/svg" |
19 | data-copyright="https://github.com/oubenruing/svg-text-animate" style="vertical-align: text-top; "> | 18 | data-copyright="https://github.com/oubenruing/svg-text-animate" style="vertical-align: text-top; "> |
@@ -166,10 +165,43 @@ | |||
166 | </path> | 165 | </path> |
167 | </g> | 166 | </g> |
168 | </svg> | 167 | </svg> |
169 | |||
170 | </div> | 168 | </div> |
171 | </div> | 169 | </div> |
172 | </div> | 170 | </div> |
173 | </body> | 171 | </body> |
174 | 172 | ||
173 | <script> | ||
174 | // 在文档加载完成后,修改标签为footer的元素的内容,为多行html | ||
175 | document.addEventListener('DOMContentLoaded', function () { | ||
176 | var footer = document.querySelector('footer'); | ||
177 | footer.innerHTML = ` | ||
178 | <span id="brand">勤倦阁©2023 </span> | ||
179 | <a id="link" href="https://beian.miit.gov.cn/">豫ICP备2023011563号-1</a> | ||
180 | `; | ||
181 | |||
182 | var brand = document.getElementById('brand'); | ||
183 | var brandStyle = window.getComputedStyle(brand); | ||
184 | var link = document.getElementById('link'); | ||
185 | |||
186 | link.style.color = brandStyle.color; | ||
187 | link.style.fontFamily = brandStyle.fontFamily; | ||
188 | link.style.fontSize = brandStyle.fontSize; | ||
189 | link.style.fontWeight = brandStyle.fontWeight; | ||
190 | // 如果需要,你还可以设置更多的样式,如文本装饰、行高等等 | ||
191 | |||
192 | // 添加鼠标移入移出事件监听器 | ||
193 | link.addEventListener('mouseenter', function () { | ||
194 | link.style.backgroundImage = 'linear-gradient(to right, violet, indigo, blue, green, yellow, orange, red)'; // 鼠标移入时设置彩虹色背景 | ||
195 | link.style.webkitBackgroundClip = 'text'; // 用于兼容webkit内核浏览器 | ||
196 | link.style.color = 'transparent'; // 使得文字透明,显示渐变色 | ||
197 | }); | ||
198 | |||
199 | link.addEventListener('mouseleave', function () { | ||
200 | link.style.backgroundImage = 'none'; // 鼠标移出时取消背景 | ||
201 | link.style.color = brandStyle.color; // 鼠标移出时恢复原始字体颜色 | ||
202 | }); | ||
203 | }); | ||
204 | |||
205 | </script> | ||
206 | |||
175 | </html> \ No newline at end of file | 207 | </html> \ No newline at end of file |