-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
636 lines (552 loc) · 179 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>对于动,静态数组使用的一些小思考</title>
<url>/2023/06/23/C++%E7%BB%83%E6%89%8B--%E9%80%9A%E8%AE%AF%E5%BD%95%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/</url>
<content><![CDATA[<iframe src="//player.bilibili.com/player.html?aid=41559729&bvid=BV1et411b73Z&cid=72983822&page=74" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
<p>这次C++练手项目是一个通讯录管理系统,跟着以上B站视频教程(P72-P83)进行开发。<br>但是,这一次练习解答和我大作业的解答格外相似,但是我用的是vector数组,我立马拿去和上一次大作业的对比,<br>这引发了我思考——<em><strong>vector动态数组</strong></em>和<em><strong>静态数组</strong></em>到底该如何做选择?<br>通过这次练习,这个问题得到解答。<br>如果想查看之前大作业的代码,可以翻阅之前发布的博客文章。</p>
<p>以下是代码</p>
<div class="highlight-container" data-rel="C++"><figure class="iseeu highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"iostream"</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MAX 1000</span></span><br><span class="line"></span><br><span class="line"><span class="type">bool</span> flag = <span class="literal">false</span>;</span><br><span class="line"><span class="type">char</span> ch;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">Person</span>{</span><br><span class="line"> string m_Name;</span><br><span class="line"> string m_Gender;</span><br><span class="line"> <span class="type">int</span> m_Age{};</span><br><span class="line"> string m_Phone;</span><br><span class="line"> string m_Address;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">AddressBook</span> {</span><br><span class="line"> Person personArray[MAX];</span><br><span class="line"> <span class="type">int</span> currentSize{};</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">menu</span><span class="params">()</span> </span>{</span><br><span class="line"> cout << <span class="string">"************************************"</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 1. add a new contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 2. search contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 3. show all contacts "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 4. delete a contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 5. modify a contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 6. clean the contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 0. exit "</span> << endl;</span><br><span class="line"> cout << <span class="string">"************************************"</span> << endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">addPerson</span><span class="params">(AddressBook *abs)</span></span>{</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="keyword">if</span> (abs->currentSize == MAX) {</span><br><span class="line"> cout << <span class="string">"通讯录已满,无法继续添加!"</span> << endl;</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> string name;</span><br><span class="line"> cout << <span class="string">"姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="comment">//添加判断,判断输入的姓名是否和数组里所储存的姓名重复</span></span><br><span class="line"> <span class="keyword">while</span> (<span class="literal">true</span>){</span><br><span class="line"> <span class="comment">//每次输入新的姓名之前都要重置 flag.</span></span><br><span class="line"> <span class="comment">//ps:我卡在这很久,想不到输入重复的名字后还得重置 flag,最后还是靠chatGPT才解决的 看来控制流程还得好好学习 :(</span></span><br><span class="line"> flag = <span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < abs->currentSize; ++i) {</span><br><span class="line"> <span class="keyword">if</span> (abs->personArray[i].m_Name == name){</span><br><span class="line"> flag = <span class="literal">true</span>;</span><br><span class="line"> cout << <span class="string">"姓名重复,请重新输入:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">if</span>(!flag) {</span><br><span class="line"> abs->personArray[abs->currentSize].m_Name = name;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> string gender;</span><br><span class="line"> cout << <span class="string">"性别:"</span>;</span><br><span class="line"> cin >> gender;</span><br><span class="line"> <span class="keyword">while</span> (<span class="literal">true</span>){</span><br><span class="line"> <span class="keyword">if</span> (gender == <span class="string">"男"</span> || gender == <span class="string">"女"</span>) { <span class="comment">//性别输入约束</span></span><br><span class="line"> abs->personArray[abs->currentSize].m_Gender = gender;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> {</span><br><span class="line"> cout << <span class="string">"输入错误,请重新输入性别:"</span> ;</span><br><span class="line"> cin >> gender;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="type">int</span> age;</span><br><span class="line"> cout << <span class="string">"年龄:"</span>;</span><br><span class="line"> cin >> age;</span><br><span class="line"> <span class="keyword">while</span>(<span class="literal">true</span>){</span><br><span class="line"> <span class="keyword">if</span> (age > <span class="number">0</span> && age < <span class="number">125</span>) { <span class="comment">//年龄区间约束</span></span><br><span class="line"> abs->personArray[abs->currentSize].m_Age = age;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> cout << <span class="string">"年龄输入区间过于离谱,请重新输入年龄:"</span> ;</span><br><span class="line"> cin >> age;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> string phone;</span><br><span class="line"> cout << <span class="string">"电话号码:"</span>;</span><br><span class="line"> cin >> phone;</span><br><span class="line"> abs->personArray[abs->currentSize].m_Phone = phone;</span><br><span class="line"> string Address;</span><br><span class="line"> cout << <span class="string">"地址:"</span>;</span><br><span class="line"> cin >> Address;</span><br><span class="line"> abs->personArray[abs->currentSize].m_Address = Address;</span><br><span class="line"> abs->currentSize++;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"添加成功!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">search</span><span class="params">( AddressBook *abs)</span></span>{</span><br><span class="line"> string name;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"请输入要查询的联系人的姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < abs->currentSize; ++i) {</span><br><span class="line"> <span class="keyword">if</span> (abs->currentSize == <span class="number">0</span>){</span><br><span class="line"> cout << <span class="string">"当前通讯录记录为空!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">if</span> (abs->personArray[i].m_Name == name){</span><br><span class="line"> cout << <span class="string">"姓名:"</span> << abs->personArray[i].m_Name << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"性别:"</span> << abs->personArray[i].m_Gender << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"年龄:"</span> << abs->personArray[i].m_Age << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"电话号码:"</span> << abs->personArray[i].m_Phone << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"地址:"</span> << abs->personArray[i].m_Address << endl;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"pause"</span>);</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> cout << <span class="string">"未找到该联系人!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">showAll</span><span class="params">(AddressBook *abs)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (abs->currentSize == <span class="number">0</span>){</span><br><span class="line"> cout << <span class="string">"当前通讯录记录为空!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < abs->currentSize; ++i) {</span><br><span class="line"> cout << <span class="string">"姓名:"</span> << abs->personArray[i].m_Name << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"性别:"</span> << abs->personArray[i].m_Gender << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"年龄:"</span> << abs->personArray[i].m_Age << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"电话号码:"</span> << abs->personArray[i].m_Phone << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"地址:"</span> << abs->personArray[i].m_Address << endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"pause"</span>);</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">deletePerson</span><span class="params">(AddressBook *abs)</span></span>{</span><br><span class="line"> string name;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"要删除的姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">0</span>; i < abs->currentSize; i++){</span><br><span class="line"> <span class="keyword">if</span>(abs->personArray[i].m_Name == name){</span><br><span class="line"> flag = <span class="literal">true</span>;</span><br><span class="line"> cout << <span class="string">"确认删除?(y/n)"</span>;</span><br><span class="line"> cin >> ch;</span><br><span class="line"> <span class="keyword">if</span>(ch == <span class="string">'y'</span> || ch == <span class="string">'Y'</span>){</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> j = i; j < abs->currentSize; j++){</span><br><span class="line"> abs->personArray[j] = abs->personArray[j+<span class="number">1</span>]; <span class="comment">//顺序表删除操作</span></span><br><span class="line"> }</span><br><span class="line"> abs->currentSize--;</span><br><span class="line"> cout << <span class="string">"删除成功!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span> cout << <span class="string">"已取消删除!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (!flag) cout << <span class="string">"未找到此人!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">modifyPerson</span><span class="params">(AddressBook *abs)</span></span>{</span><br><span class="line"> string name;</span><br><span class="line"> <span class="type">int</span> selection;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"输入要修改的联系人信息的姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < abs->currentSize; ++i) {</span><br><span class="line"> <span class="keyword">if</span> (name == abs->personArray[i].m_Name) {</span><br><span class="line"> flag = <span class="literal">true</span>; <span class="comment">//原本课程里需要重新逐一输入信息,比较麻烦,所以这里添加修改选项</span></span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> cout << <span class="string">" 1.姓名 2.电话号码 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 3.性别 4.年龄 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 5.地址 0.返回 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 请输入相应编号做相应修改。 "</span> << endl;</span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> cin >> selection;</span><br><span class="line"> <span class="keyword">switch</span> (selection) {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: {cout << <span class="string">"新的姓名信息:"</span>; cin >> abs->personArray[i].m_Name; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: {cout << <span class="string">"新的电话号码信息:"</span>; cin >> abs->personArray[i].m_Phone; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: {cout << <span class="string">"新的性别信息:"</span>; cin >> abs->personArray[i].m_Gender; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>: {cout << <span class="string">"新的年龄信息:"</span>; cin >> abs->personArray[i].m_Age; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">5</span>: {cout << <span class="string">"新的地址信息:"</span>; cin >> abs->personArray[i].m_Address; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: <span class="built_in">system</span>(<span class="string">"cls"</span>); <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">default</span>:cout << <span class="string">"输入错误!"</span> << endl; <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">if</span> (!flag) cout << <span class="string">"查无此人!"</span> << endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">cleanAll</span><span class="params">(AddressBook *abs)</span> </span>{</span><br><span class="line"> cout << <span class="string">"确认全部清除?(y/n)"</span>;</span><br><span class="line"> cin >> ch;</span><br><span class="line"> <span class="keyword">if</span>(ch == <span class="string">'y'</span> || ch == <span class="string">'Y'</span>){</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < abs->currentSize; ++i) {</span><br><span class="line"> abs->personArray[i].m_Name.<span class="built_in">clear</span>();</span><br><span class="line"> abs->personArray[i].m_Gender.<span class="built_in">clear</span>();</span><br><span class="line"> abs->personArray[i].m_Age = <span class="number">0</span>;</span><br><span class="line"> abs->personArray[i].m_Phone.<span class="built_in">clear</span>();</span><br><span class="line"> abs->personArray[i].m_Address.<span class="built_in">clear</span>();</span><br><span class="line"> abs->currentSize = <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> cout << <span class="string">"所有联系人信息均已消除!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span> cout << <span class="string">"删除取消!"</span> << endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> AddressBook abs;</span><br><span class="line"> abs.currentSize = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(<span class="literal">true</span>){</span><br><span class="line"> <span class="built_in">menu</span>();</span><br><span class="line"> <span class="type">int</span> selection = <span class="number">0</span>;</span><br><span class="line"> cin >> selection;</span><br><span class="line"> <span class="keyword">switch</span> (selection) {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: <span class="built_in">addPerson</span>(&abs);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: <span class="built_in">search</span>(&abs);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: <span class="built_in">showAll</span>(&abs);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>: <span class="built_in">deletePerson</span>(&abs);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">5</span>: <span class="built_in">modifyPerson</span>(&abs);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">6</span>: <span class="built_in">cleanAll</span>(&abs);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: cout << <span class="string">"Bye!"</span> << endl; <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">default</span>: cout << <span class="string">"Input Error! Please input a valid number."</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<p>下面是将静态数组换成vector动态数组的码子</p>
<div class="highlight-container" data-rel="C++"><figure class="iseeu highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"iostream"</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"vector"</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MAX 1000</span></span><br><span class="line"></span><br><span class="line"><span class="type">bool</span> flag = <span class="literal">false</span>;</span><br><span class="line"><span class="type">char</span> ch;</span><br><span class="line"></span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">Person</span>{</span><br><span class="line"> string m_Name;</span><br><span class="line"> string m_Gender;</span><br><span class="line"> <span class="type">int</span> m_Age{};</span><br><span class="line"> string m_Phone;</span><br><span class="line"> string m_Address;</span><br><span class="line">};</span><br><span class="line">vector<Person> persons;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">menu</span><span class="params">()</span> </span>{</span><br><span class="line"> cout << <span class="string">"************************************"</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 1. add a new contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 2. search contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 3. show all contacts "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 4. delete a contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 5. modify a contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 6. clean the contact "</span> << endl;</span><br><span class="line"> cout << <span class="string">"* 0. exit "</span> << endl;</span><br><span class="line"> cout << <span class="string">"************************************"</span> << endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">addPerson</span><span class="params">()</span></span>{</span><br><span class="line"> Person person;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="keyword">if</span> (persons.<span class="built_in">size</span>() == MAX) {</span><br><span class="line"> cout << <span class="string">"通讯录已满,无法继续添加!"</span> << endl;</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> string name;</span><br><span class="line"> cout << <span class="string">"姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">while</span> (<span class="literal">true</span>){</span><br><span class="line"> flag = <span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < persons.<span class="built_in">size</span>(); ++i) {</span><br><span class="line"> <span class="keyword">if</span> (person.m_Name == name){</span><br><span class="line"> flag = <span class="literal">true</span>;</span><br><span class="line"> cout << <span class="string">"姓名重复,请重新输入:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">if</span>(!flag) {</span><br><span class="line"> person.m_Name = name;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> string gender;</span><br><span class="line"> cout << <span class="string">"性别:"</span>;</span><br><span class="line"> cin >> gender;</span><br><span class="line"> <span class="keyword">while</span> (<span class="literal">true</span>){</span><br><span class="line"> <span class="keyword">if</span> (gender == <span class="string">"男"</span> || gender == <span class="string">"女"</span>) { </span><br><span class="line"> person.m_Gender = gender;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> {</span><br><span class="line"> cout << <span class="string">"输入错误,请重新输入性别:"</span> ;</span><br><span class="line"> cin >> gender;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="type">int</span> age;</span><br><span class="line"> cout << <span class="string">"年龄:"</span>;</span><br><span class="line"> cin >> age;</span><br><span class="line"> <span class="keyword">while</span>(<span class="literal">true</span>){</span><br><span class="line"> <span class="keyword">if</span> (age > <span class="number">0</span> && age < <span class="number">125</span>) { </span><br><span class="line"> person.m_Age = age;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> cout << <span class="string">"年龄输入区间过于离谱,请重新输入年龄:"</span> ;</span><br><span class="line"> cin >> age;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> string phone;</span><br><span class="line"> cout << <span class="string">"电话号码:"</span>;</span><br><span class="line"> cin >> phone;</span><br><span class="line"> person.m_Phone = phone;</span><br><span class="line"> string Address;</span><br><span class="line"> cout << <span class="string">"地址:"</span>;</span><br><span class="line"> cin >> Address;</span><br><span class="line"> person.m_Address = Address;</span><br><span class="line"> persons.<span class="built_in">push_back</span>(person);</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"添加成功!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">search</span><span class="params">()</span></span>{</span><br><span class="line"> string name;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"请输入要查询的联系人的姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span>& person : persons) {</span><br><span class="line"> <span class="keyword">if</span> (persons.<span class="built_in">empty</span>()){</span><br><span class="line"> cout << <span class="string">"当前通讯录记录为空!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">if</span> (person.m_Name == name){</span><br><span class="line"> cout << <span class="string">"姓名:"</span> << person.m_Name << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"性别:"</span> << person.m_Gender << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"年龄:"</span> << person.m_Age << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"电话号码:"</span> << person.m_Phone << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"地址:"</span> << person.m_Address << endl;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"pause"</span>);</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> cout << <span class="string">"未找到该联系人!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">showAll</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (persons.<span class="built_in">empty</span>()){</span><br><span class="line"> cout << <span class="string">"当前通讯录记录为空!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span>& person : persons) {</span><br><span class="line"> cout << <span class="string">"姓名:"</span> << person.m_Name << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"性别:"</span> << person.m_Gender << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"年龄:"</span> << person.m_Age << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"电话号码:"</span> << person.m_Phone << <span class="string">"\t"</span>;</span><br><span class="line"> cout << <span class="string">"地址:"</span> << person.m_Address << endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"pause"</span>);</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">deletePerson</span><span class="params">()</span></span>{</span><br><span class="line"> string name;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"要删除的姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">0</span>; i < persons.<span class="built_in">size</span>(); i++){</span><br><span class="line"> <span class="keyword">if</span>(persons[i].m_Name == name){</span><br><span class="line"> flag = <span class="literal">true</span>;</span><br><span class="line"> cout << <span class="string">"确认删除?(y/n)"</span>;</span><br><span class="line"> cin >> ch;</span><br><span class="line"> <span class="keyword">if</span>(ch == <span class="string">'y'</span> || ch == <span class="string">'Y'</span>){</span><br><span class="line"> persons.<span class="built_in">erase</span>(persons.<span class="built_in">begin</span>() + i);</span><br><span class="line"> cout << <span class="string">"删除成功!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span> cout << <span class="string">"已取消删除!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (!flag) cout << <span class="string">"未找到此人!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">modifyPerson</span><span class="params">()</span></span>{</span><br><span class="line"> string name;</span><br><span class="line"> <span class="type">int</span> selection;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"输入要修改的联系人信息的姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">auto</span> &person : persons) {</span><br><span class="line"> <span class="keyword">if</span> (name == person.m_Name) {</span><br><span class="line"> flag = <span class="literal">true</span>; </span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> cout << <span class="string">" 1.姓名 2.电话号码 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 3.性别 4.年龄 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 5.地址 0.返回 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 请输入相应编号做相应修改。 "</span> << endl;</span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> cin >> selection;</span><br><span class="line"> <span class="keyword">switch</span> (selection) {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: {cout << <span class="string">"新的姓名信息:"</span>; cin >> person.m_Name; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: {cout << <span class="string">"新的电话号码信息:"</span>; cin >> person.m_Phone; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: {cout << <span class="string">"新的性别信息:"</span>; cin >> person.m_Gender; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>: {cout << <span class="string">"新的年龄信息:"</span>; cin >> person.m_Age; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">5</span>: {cout << <span class="string">"新的地址信息:"</span>; cin >> person.m_Address; cout << <span class="string">"修改成功"</span> << endl; <span class="keyword">break</span>;}</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: <span class="built_in">system</span>(<span class="string">"cls"</span>); <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">default</span>:cout << <span class="string">"输入错误!"</span> << endl; <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">if</span> (!flag) cout << <span class="string">"查无此人!"</span> << endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">cleanAll</span><span class="params">()</span> </span>{</span><br><span class="line"> cout << <span class="string">"确认全部清除?(y/n)"</span>;</span><br><span class="line"> cin >> ch;</span><br><span class="line"> <span class="keyword">if</span>(ch == <span class="string">'y'</span> || ch == <span class="string">'Y'</span>){</span><br><span class="line"> persons.<span class="built_in">clear</span>();</span><br><span class="line"> cout << <span class="string">"所有联系人信息均已消除!"</span> << endl;</span><br><span class="line"> }<span class="keyword">else</span> cout << <span class="string">"删除取消!"</span> << endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">while</span>(<span class="literal">true</span>){</span><br><span class="line"> <span class="built_in">menu</span>();</span><br><span class="line"> <span class="type">int</span> selection = <span class="number">0</span>;</span><br><span class="line"> cin >> selection;</span><br><span class="line"> <span class="keyword">switch</span> (selection) {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: <span class="built_in">addPerson</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: <span class="built_in">search</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: <span class="built_in">showAll</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>: <span class="built_in">deletePerson</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">5</span>: <span class="built_in">modifyPerson</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">6</span>: <span class="built_in">cleanAll</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: cout << <span class="string">"Bye!"</span> << endl; <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">default</span>: cout << <span class="string">"Input Error! Please input a valid number."</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<p>静态数组和vector动态数组各有千秋:</p>
<p> <strong>Vector动态数组:</strong></p>
<ol>
<li><p><strong>动态大小</strong>:Vector 是一个动态容器,可以根据需要在运行时调整大小。它能够自动处理内存管理和扩展,而无需显式指定初始大小(与静态数组不同)。这使得 Vector 更加灵活,能够适应动态的数据需求。</p>
</li>
<li><p><strong>安全性</strong>:Vector 具有边界检查功能,可以确保访问元素时不会越界,减少了程序崩溃或发生其他错误的风险。而静态数组没有内置的边界检查机制,如果不小心越界访问,可能会导致未定义的行为。</p>
</li>
<li><p><strong>方便的操作和函数</strong>:Vector 对象提供了方便的成员函数和算法,如插入、删除、排序等操作。而静态数组通常需要手动编写这些操作的代码,相对来说更加繁琐。</p>
</li>
<li><p><strong>可以返回长度</strong>:Vector 有 <code>size()</code> 成员函数用于获取当前容器中元素的数量,而对于静态数组,需要使用额外变量或固定长度进行追踪。</p>
</li>
<li><p><strong>可以作为函数参数和返回值</strong>:Vector 可以直接作为函数的参数和返回值传递,而静态数组传递时需要指定数组大小,且容易造成内存浪费或限制传递的数组大小。</p>
</li>
</ol>
<p> <strong>静态数组:</strong></p>
<ol>
<li><strong>内存效率</strong>:静态数组在编译时就分配了连续的内存空间,并且没有额外的运行时开销。这使得静态数组在内存访问方面更加紧凑和高效,能够提高数据访问的局部性和缓存命中率,从而提升访问性能。</li>
<li><strong>简单和直观</strong>:静态数组是一种基本的数据结构,使用起来非常简单和直观。只需声明数组并指定大小,即可直接访问和操作数组元素。</li>
<li><strong>编译时确定大小</strong>:静态数组的大小在编译时确定,无法动态改变。这可以作为一种约束,确保不会超出预期的数组范围,并在编译时发现潜在的错误。</li>
<li><strong>不涉及动态内存管理</strong>:由于静态数组在编译时分配了固定大小的内存,因此不存在动态内存管理的问题。这样可以避免动态内存分配和释放带来的开销和内存碎片问题。</li>
<li><strong>适用于小规模数据集</strong>:对于小规模的数据集,静态数组的性能优势通常是微不足道的。与 Vector 数组相比,静态数组可能具有更低的内存开销和更高的执行效率。</li>
</ol>
<p>在选择使用静态数组还是 Vector 数组时,需要综合考虑具体场景、数据规模和操作需求,并权衡各自的优缺点。</p>
<p>开发截图</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202306231924606.png"
></p>
]]></content>
<tags>
<tag>C++</tag>
<tag>通讯录管理系统</tag>
<tag>数组</tag>
</tags>
</entry>
<entry>
<title>C++编写学生信息管理系统</title>
<url>/2023/01/04/C++%E7%BC%96%E5%86%99%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F/</url>
<content><![CDATA[<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>这个是我的一个大作业,记录下这个大作业的源代码。</p>
<h1 id="题目要求"><a href="#题目要求" class="headerlink" title="题目要求"></a>题目要求</h1><p>1.功能内容必须包含以下内容:</p>
<p> 对记录进行<u>增加、删除、查询、修改、浏览</u>等操作。</p>
<p>2.编程使用的技术必须包含以下C++语言知识点:</p>
<p> (1) 变量的使用</p>
<p> (2) if语句</p>
<p> (3) switch case分支语句的使用</p>
<p> (4) 循环结构</p>
<p> (5) 函数定义及调用</p>
<p> (6) 类的定义及用法</p>
<h1 id="代码缺点:"><a href="#代码缺点:" class="headerlink" title="代码缺点:"></a>代码缺点:</h1><p>因为本人技术问题,添加学生信息后就只是一次性的,并没有储存到本地,所以一旦关闭系统后所添加的信息都会消失。</p>
<h1 id="交互界面截图:"><a href="#交互界面截图:" class="headerlink" title="交互界面截图:"></a>交互界面截图:</h1><h3 id="1-主界面:"><a href="#1-主界面:" class="headerlink" title="1.主界面:"></a>1.主界面:</h3><p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202301041745520.png"
></p>
<h3 id="2-添加学生信息:"><a href="#2-添加学生信息:" class="headerlink" title="2.添加学生信息:"></a>2.添加学生信息:</h3><p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202301041840614.png"
></p>
<h3 id="3-查询学生信息:"><a href="#3-查询学生信息:" class="headerlink" title="3.查询学生信息:"></a>3.查询学生信息:</h3><p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202301041841424.png"
></p>
<h4 id="(1)查询结果:"><a href="#(1)查询结果:" class="headerlink" title="(1)查询结果:"></a>(1)查询结果:</h4><p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202301041842926.png"
></p>
<h3 id="4-修改学生信息:"><a href="#4-修改学生信息:" class="headerlink" title="4.修改学生信息:"></a>4.修改学生信息:</h3><p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202301041843903.png"
></p>
<h1 id="我搓的代码"><a href="#我搓的代码" class="headerlink" title="我搓的代码"></a>我搓的代码</h1><div class="highlight-container" data-rel="C++"><figure class="iseeu highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"iostream"</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"string"</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> M 60</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span></span><br><span class="line">{</span><br><span class="line"><span class="keyword">private</span>:</span><br><span class="line"> std::string num;</span><br><span class="line"> std::string name;</span><br><span class="line"> <span class="type">int</span> age;</span><br><span class="line"> std::string sex;</span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line"> <span class="function"><span class="keyword">explicit</span> <span class="title">Student</span><span class="params">(std::string =<span class="string">""</span>,std::string =<span class="string">""</span>,<span class="type">int</span> = <span class="number">10</span>,std::string = <span class="string">"男"</span>)</span></span>;</span><br><span class="line"> <span class="function">std::string <span class="title">getNum</span><span class="params">()</span></span>;</span><br><span class="line"> <span class="function">std::string <span class="title">getName</span><span class="params">()</span></span>;</span><br><span class="line"> <span class="function"><span class="type">void</span> <span class="title">setName</span><span class="params">(std::string n)</span></span>;</span><br><span class="line"> <span class="function"><span class="type">void</span> <span class="title">setSex</span><span class="params">(<span class="type">char</span> s)</span></span>;</span><br><span class="line"> <span class="function"><span class="type">void</span> <span class="title">setAge</span><span class="params">(<span class="type">int</span> a)</span></span>;</span><br><span class="line"> <span class="function"><span class="type">void</span> <span class="title">setNum</span><span class="params">(std::string u)</span></span>;</span><br><span class="line"> <span class="function"><span class="type">void</span> <span class="title">print</span><span class="params">()</span></span>;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">addStudent</span><span class="params">(Student *s ,<span class="type">int</span> &count)</span></span>;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">deleteStudent</span><span class="params">(Student *s ,<span class="type">int</span> &count)</span></span>;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">updateStudent</span><span class="params">(Student *s ,<span class="type">int</span> count)</span></span>;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">searchStudent</span><span class="params">(Student *s ,<span class="type">int</span> count)</span></span>;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">menu</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line">Student::<span class="built_in">Student</span>(std::string n1,std::string n2,<span class="type">int</span> a,std::string s)</span><br><span class="line">{</span><br><span class="line"> age = a;</span><br><span class="line"> num = std::<span class="built_in">move</span>(n1);</span><br><span class="line"> name = std::<span class="built_in">move</span>(n2);</span><br><span class="line"> sex = std::<span class="built_in">move</span>(s);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">Student::print</span><span class="params">()</span> </span>{</span><br><span class="line"> std::cout << <span class="string">"学生名字:"</span> << name << <span class="string">" "</span> << <span class="string">"学号:"</span> << num << <span class="string">" "</span> << <span class="string">"年龄:"</span> << age << <span class="string">" "</span> << <span class="string">"性别:"</span> << sex << <span class="string">" "</span> << std::endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">Student::setNum</span><span class="params">(std::string u)</span> </span>{num = std::<span class="built_in">move</span>(u);}</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">Student::setName</span><span class="params">(std::string n)</span> </span>{name=std::<span class="built_in">move</span>(n);}</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">Student::setAge</span><span class="params">(<span class="type">int</span> a)</span> </span>{age = a;}</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">Student::setSex</span><span class="params">(<span class="type">char</span> s)</span> </span>{sex=s;}</span><br><span class="line"><span class="function">std::string <span class="title">Student::getName</span><span class="params">()</span> </span>{<span class="keyword">return</span> name;}</span><br><span class="line"><span class="function">std::string <span class="title">Student::getNum</span><span class="params">()</span> </span>{<span class="keyword">return</span> num;}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">menu</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> std::cout << <span class="string">"-----------------------------------------------"</span> << std::endl;</span><br><span class="line"> std::cout << std::endl;</span><br><span class="line"> std::cout<< <span class="string">" 六年级二班学生信息系统 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 1.添加学生信息 2.查询学生信息 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 3.修改学生信息 4.删除学生信息 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 0.退出系统 "</span> << std::endl;</span><br><span class="line"> std::cout << std::endl;</span><br><span class="line"> std::cout << <span class="string">"-----------------------------------------------"</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 请输入0-4进行相应操作 "</span> << std::endl;</span><br><span class="line"> <span class="type">int</span> n;</span><br><span class="line"> std::cin >> n;</span><br><span class="line"> <span class="keyword">return</span> n;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">addStudent</span><span class="params">(Student *s,<span class="type">int</span> &count)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="type">int</span> age;</span><br><span class="line"> std::string num,name;</span><br><span class="line"> std::string sex;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> std::cout << <span class="string">"请输入学生信息:"</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">"学生姓名:"</span>;</span><br><span class="line"> std::cin >> name;</span><br><span class="line"> std::cout << <span class="string">"学号:"</span>;</span><br><span class="line"> std::cin >> num;</span><br><span class="line"> std::cout << <span class="string">"性别:"</span>;</span><br><span class="line"> std::cin >> sex;</span><br><span class="line"> std::cout << <span class="string">"年龄:"</span>;</span><br><span class="line"> std::cin >> age;</span><br><span class="line"> s[count]=<span class="built_in">Student</span>(num,name,age,sex);</span><br><span class="line"> count++;</span><br><span class="line"> std::cout << <span class="string">"添加成功"</span> << std::endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">deleteStudent</span><span class="params">(Student *s,<span class="type">int</span> &count)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="type">int</span> i, j, flag;</span><br><span class="line"> <span class="type">char</span> ch;</span><br><span class="line"> flag = <span class="number">0</span>;</span><br><span class="line"> std::string newname;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> std::cout << <span class="string">"请输入删除姓名:"</span>;</span><br><span class="line"> std::cin >> newname;</span><br><span class="line"> <span class="keyword">for</span> (i = <span class="number">0</span>; i < count; i++) {</span><br><span class="line"> <span class="keyword">if</span> (s[i].<span class="built_in">getName</span>() == newname) {</span><br><span class="line"> flag = <span class="number">1</span>;</span><br><span class="line"> std::cout << <span class="string">"学号:"</span> << i+<span class="number">1</span> << std::endl;</span><br><span class="line"> s[i].<span class="built_in">print</span>();</span><br><span class="line"> std::cout << <span class="string">" 确认是否进行删除,请输入y/n."</span>;</span><br><span class="line"> std::cin >> ch;</span><br><span class="line"> <span class="keyword">if</span> (ch == <span class="string">'y'</span> || ch == <span class="string">'Y'</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span> (j=i+<span class="number">1</span>; j<count; j++)</span><br><span class="line"> s[j<span class="number">-1</span>] = s[j];</span><br><span class="line"> count--;</span><br><span class="line"> std::cout << <span class="string">"删除成功"</span> << std::endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> std::cout << <span class="string">"放弃本次删除操作"</span> << std::endl;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (flag == <span class="number">0</span>) {</span><br><span class="line"> std::cout << <span class="string">"不存在符合条件的学生信息!"</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">updateStudent</span><span class="params">(Student *s,<span class="type">int</span> count)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="type">int</span> i,type;</span><br><span class="line"> std::string num;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> std::cout << <span class="string">"请输入修改学生学号:"</span> << std::endl;</span><br><span class="line"> std::cin >> num;</span><br><span class="line"> <span class="keyword">for</span> ( i = <span class="number">0</span>; i < count && (s[i].<span class="built_in">getNum</span>()!= num); i++);</span><br><span class="line"> <span class="keyword">if</span> (i < count )</span><br><span class="line"> {</span><br><span class="line"> s[i].<span class="built_in">print</span>();</span><br><span class="line"> std::cout << <span class="string">"-----------------------------------------------"</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 1.姓名 2.学号 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 3.性别 4.年龄 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 0.返回 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 请输入相应编号做相应修改。 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">"-----------------------------------------------"</span> << std::endl;</span><br><span class="line"> std::cin >> type;</span><br><span class="line"> <span class="keyword">switch</span> (type)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line"> {</span><br><span class="line"> std::string newname;</span><br><span class="line"> std::cout << <span class="string">"请输入新的姓名:"</span> << std::endl;</span><br><span class="line"> std::cin >> newname;</span><br><span class="line"> s[i].<span class="built_in">setName</span>(newname);</span><br><span class="line"> std::cout << <span class="string">"修改成功"</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line"> {</span><br><span class="line"> std::string newnum;</span><br><span class="line"> std::cout << <span class="string">"请输入新的学号:"</span> << std::endl;</span><br><span class="line"> std::cin >> newnum;</span><br><span class="line"> s[i].<span class="built_in">setNum</span>(newnum);</span><br><span class="line"> std::cout << <span class="string">"修改成功"</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line"> {</span><br><span class="line"> <span class="type">char</span> newsex;</span><br><span class="line"> std::cout << <span class="string">"请输入新的性别(F:女 f:男):"</span> << std::endl;</span><br><span class="line"> std::cin >> newsex;</span><br><span class="line"> s[i].<span class="built_in">setSex</span>(newsex);</span><br><span class="line"> std::cout << <span class="string">"修改成功"</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>:</span><br><span class="line"> {</span><br><span class="line"> <span class="type">int</span> newage;</span><br><span class="line"> std::cout << <span class="string">"请输入新的年龄:"</span> << std::endl;</span><br><span class="line"> std::cin >> newage;</span><br><span class="line"> s[i].<span class="built_in">setAge</span>(newage);</span><br><span class="line"> std::cout << <span class="string">"修改成功"</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">default</span>:</span><br><span class="line"> std::cout << <span class="string">"输入错误"</span> << std::endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> std::cout << <span class="string">"不存在符合条件的学生记录"</span> << std::endl;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">searchStudent</span><span class="params">(Student *s,<span class="type">int</span> count)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="type">int</span> type,flag;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="keyword">while</span> (<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> std::cout << <span class="string">"-----------------------------------------------"</span> << std::endl;</span><br><span class="line"> std::cout << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 1.按姓名查询 2.按学号查询 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 0.返回 "</span> << std::endl;</span><br><span class="line"> std::cout << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 请输入0至2 "</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">"-----------------------------------------------"</span> << std::endl;</span><br><span class="line"> std::cin >> type;</span><br><span class="line"> <span class="keyword">switch</span> (type)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line"> {</span><br><span class="line"> std::string newname;</span><br><span class="line"> std::cout << <span class="string">"请查询输入姓名:"</span>;</span><br><span class="line"> std::cin >> newname;</span><br><span class="line"> flag = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < count; i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (s[i].<span class="built_in">getName</span>() == newname)</span><br><span class="line"> {</span><br><span class="line"> s[i].<span class="built_in">print</span>();</span><br><span class="line"> flag = <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (flag == <span class="number">0</span>)</span><br><span class="line"> std::cout << <span class="string">"不存在符合条件的学生"</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line"> {</span><br><span class="line"> std::string newnum;</span><br><span class="line"> std::cout << <span class="string">"请输入学号:"</span>;</span><br><span class="line"> std::cin >> newnum;</span><br><span class="line"> flag = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < count ;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span> (s[i].<span class="built_in">getNum</span>() == newnum)</span><br><span class="line"> {</span><br><span class="line"> s[i].<span class="built_in">print</span>();</span><br><span class="line"> flag = <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (flag == <span class="number">0</span>)</span><br><span class="line"> std::cout << <span class="string">"不存在符合条件的学生"</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">default</span>: std::cout << <span class="string">"输入错误 "</span> << std::endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> Student s[M];</span><br><span class="line"> <span class="type">int</span> count = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span> (<span class="number">1</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">switch</span>(<span class="built_in">menu</span>())</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line"> <span class="built_in">addStudent</span>(s,count);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line"> <span class="built_in">searchStudent</span>(s,count);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line"> <span class="built_in">updateStudent</span>(s,count);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>:</span><br><span class="line"> <span class="built_in">deleteStudent</span>(s,count);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line"> <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">default</span>:</span><br><span class="line"> std::cout << <span class="string">"输入错误,请重新输入!"</span> << std::endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<p>文章更新:</p>
<p>时间:2023年2月13日18点10分</p>
<p>卧槽,刚才让chatGPT写我的C++大作业。代码写的比我好几百倍 ,代码原本是用结构体,我把结构体换成类再作修改就符合题目要求,且使用效果更好。代码写的比我好几百倍,看的我人都傻了,让我大受震撼。主要是代码里对vector和Range-based for loop的使用能够大大简化代码(相对于我写的)。简化内存管理、提高代码效率、提供高效的插入和删除操作,并且易于使用和理解。</p>
<div class="highlight-container" data-rel="C++"><figure class="iseeu highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><string></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><vector></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span>{</span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line"> string name;</span><br><span class="line"> <span class="type">int</span> age{<span class="string">'0'</span>},num{<span class="string">'0'</span>};</span><br><span class="line"> string gender;</span><br><span class="line"> string address;</span><br><span class="line">};</span><br><span class="line">vector<Student> students;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">addStudent</span><span class="params">()</span> </span>{</span><br><span class="line"> Student student;</span><br><span class="line"> cout << <span class="string">"请输入学生姓名:"</span>;</span><br><span class="line"> cin >> student.name;</span><br><span class="line"> cout << <span class="string">"请输入学生学号:"</span>;</span><br><span class="line"> cin >> student.num;</span><br><span class="line"> cout << <span class="string">"请输入学生年龄:"</span>;</span><br><span class="line"> cin >> student.age;</span><br><span class="line"> cout << <span class="string">"请输入学生性别:"</span>;</span><br><span class="line"> cin >> student.gender;</span><br><span class="line"> cout << <span class="string">"请输入学生地址:"</span>;</span><br><span class="line"> cin >> student.address;</span><br><span class="line"> students.<span class="built_in">push_back</span>(student);</span><br><span class="line"> cout << <span class="string">"添加成功!"</span> << endl;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">deleteStudent</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="type">bool</span> flag = <span class="literal">false</span>;</span><br><span class="line"> <span class="type">char</span> ch;</span><br><span class="line"> string name;</span><br><span class="line"> cout << <span class="string">"请输入要删除的学生姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < students.<span class="built_in">size</span>(); i++){</span><br><span class="line"> <span class="keyword">if</span> (students[i].name == name){</span><br><span class="line"> flag = <span class="literal">true</span>;</span><br><span class="line"> cout << <span class="string">"确认是否进行删除,请输入y/n."</span>;</span><br><span class="line"> cin >> ch;</span><br><span class="line"> <span class="keyword">if</span> (ch == <span class="string">'y'</span> || ch == <span class="string">'Y'</span>){</span><br><span class="line"> students.<span class="built_in">erase</span>(students.<span class="built_in">begin</span>() + i);</span><br><span class="line"> cout << <span class="string">"删除成功!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> cout << <span class="string">"放弃本次删除操作"</span> << endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (!flag){</span><br><span class="line"> cout << <span class="string">"未找到该学生!"</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">modifyStudent</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="type">int</span> type;</span><br><span class="line"> string name;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"请输入要修改的学生姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">auto</span> & student : students){</span><br><span class="line"> <span class="keyword">if</span> (student.name == name){</span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> cout << <span class="string">" 1.姓名 2.学号 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 3.性别 4.年龄 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 5.地址 0.返回 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 请输入相应编号做相应修改。 "</span> << endl;</span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> cin >> type;</span><br><span class="line"> <span class="keyword">switch</span> (type){</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>:{</span><br><span class="line"> cout << <span class="string">"请输入学生新的姓名:"</span>;</span><br><span class="line"> cin >> student.name;</span><br><span class="line"> cout << <span class="string">"修改成功!"</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>:{</span><br><span class="line"> cout << <span class="string">"请输入学生新的学号:"</span>;</span><br><span class="line"> cin >>student.num;</span><br><span class="line"> cout << <span class="string">"修改成功!"</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>:{</span><br><span class="line"> cout << <span class="string">"请输入学生新的性别:"</span>;</span><br><span class="line"> cin >> student.gender;</span><br><span class="line"> cout << <span class="string">"修改成功!"</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>:{</span><br><span class="line"> cout << <span class="string">"请输入学生新的年龄:"</span>;</span><br><span class="line"> cin >> student.age;</span><br><span class="line"> cout << <span class="string">"修改成功!"</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">5</span>:{</span><br><span class="line"> cout << <span class="string">"请输入学生新的地址:"</span>;</span><br><span class="line"> cin >> student.address;</span><br><span class="line"> cout << <span class="string">"修改成功!"</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>:{</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">default</span>:</span><br><span class="line"> cout << <span class="string">"输入错误"</span> << endl;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> cout << <span class="string">"未找到您所输入的学生。"</span> << endl;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">queryStudent</span><span class="params">()</span></span>{</span><br><span class="line"> string name;</span><br><span class="line"> <span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> cout << <span class="string">"请输入要查询的学生姓名:"</span>;</span><br><span class="line"> cin >> name;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">auto</span> & student : students){</span><br><span class="line"> <span class="keyword">if</span> (student.name == name){</span><br><span class="line"> cout << <span class="string">"姓名:"</span> << student.name << endl;</span><br><span class="line"> cout << <span class="string">"年龄:"</span> << student.age << endl;</span><br><span class="line"> cout << <span class="string">"学号:"</span> << student.num << endl;</span><br><span class="line"> cout << <span class="string">"性别:"</span> << student.gender << endl;</span><br><span class="line"> cout << <span class="string">"地址:"</span> << student.address << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> } <span class="keyword">else</span> cout << <span class="string">"未找到该学生!"</span> << endl;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">while</span> (<span class="literal">true</span>){</span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> cout << <span class="string">" 六年级二班学生信息系统 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 1.添加学生信息 2.删除学生信息 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 3.修改学生信息 4.查询学生信息 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 0.退出系统 "</span> << endl;</span><br><span class="line"> cout << <span class="string">" 请输入相应编号做相应修改。 "</span> << endl;</span><br><span class="line"> cout << <span class="string">"-----------------------------------------------"</span> << endl;</span><br><span class="line"> <span class="type">int</span> n;</span><br><span class="line"> cin >> n;</span><br><span class="line"> <span class="keyword">switch</span> (n){</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line"> <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line"> <span class="built_in">addStudent</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line"> <span class="built_in">deleteStudent</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line"> <span class="built_in">modifyStudent</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">4</span>:</span><br><span class="line"> <span class="built_in">queryStudent</span>();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">default</span>:</span><br><span class="line"> cout << <span class="string">"输入错误!"</span> << endl;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
]]></content>
<tags>
<tag>C++</tag>
<tag>学生信息管理系统</tag>
</tags>
</entry>
<entry>
<title>部署博客后打开网站显示404</title>
<url>/2024/09/16/Hexo%E9%83%A8%E7%BD%B2%E9%97%AE%E9%A2%98/</url>
<content><![CDATA[<p>我把Node.js更新到v22.8.0,接着更新了Hexo,</p>
<p>最后我部署完后发现博客404了,但是hexo s 正常显示,于是我认为是部署出了问题,</p>
<p>所以检查了博客根目录下的**.deploy_git<strong>文件夹,</strong>发现里面没有任何东西**。</p>
<p>首先,我用taobao源重新安装了hexo-deployer-git</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">cnpm un hexo-deployer-git</span><br><span class="line">cnpm i hexojs/hexo-deployer-git</span><br></pre></td></tr></table></figure></div>
<p>然后:</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">Hexo clean</span><br><span class="line">hexo g </span><br><span class="line">hexo d</span><br></pre></td></tr></table></figure></div>
<p>打开博客发现无济于事。</p>
<hr>
<p>正当我焦头烂额时, 在无意间瞥到了终端的这张图,加上先前看到的下面这个相关问题的帖子,发觉到可能是Node.js版本过新</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/2024_09_16_22.8.0.png"
></p>
<p>帖子: <a class="link" href="https://blog.csdn.net/qq_45865697/article/details/121892998" >https://blog.csdn.net/qq_45865697/article/details/121892998</a></p>
<p>我去看了眼hexo-deployer-git 最新版的发布日期,发现是2023年2月6号,基本确定原因是<em><strong>Node.js版本过新</strong></em></p>
<p>于是把node.js换成v20.17.0 (LTS) 版本</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/2024_09_16_v20.17.0_node.png"
></p>
<p>重新部署网址,成功解决!</p>
<p>这次给了我一个教训:<strong>不要随便更新Node.js!</strong></p>
<p>下面的帖子也是和我一样的情况:</p>
<p><a class="link" href="https://ten-z.github.io/2022/03/17/Hexo-Github%E5%8D%9A%E5%AE%A2%E7%A7%BB%E6%A4%8D%E5%8F%8A%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98/" >https://ten-z.github.io/2022/03/17/Hexo-Github%E5%8D%9A%E5%AE%A2%E7%A7%BB%E6%A4%8D%E5%8F%8A%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98/</a></p>
<p>下面有其他的Hexo部署插件:</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://hexo.io/zh-cn/docs/one-command-deployment</span><br><span class="line">https://hexo.io/plugins/</span><br></pre></td></tr></table></figure></div>
<p>更新Hexo:</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line"># 使用淘宝源的 cnpm 替换 npm</span><br><span class="line">npm install -g cnpm --registry=https://registry.npm.taobao.org</span><br><span class="line"></span><br><span class="line">cnpm install -g cnpm # 升级 npm</span><br><span class="line">cnpm cache clean -f # 清除 npm 缓存</span><br><span class="line"></span><br><span class="line">===更新 hexo: 进入 blog 目录,执行如下命令=== </span><br><span class="line"># 更新 package.json 中的 hexo 及个插件版本</span><br><span class="line">cnpm install -g npm-check # 检查之前安装的插件,都有哪些是可以升级的 </span><br><span class="line">cnpm install -g npm-upgrade # 升级系统中的插件</span><br><span class="line">npm-check</span><br><span class="line">npm-upgrade</span><br><span class="line"></span><br><span class="line"># 更新 hexo 及所有插件</span><br><span class="line">cnpm update</span><br><span class="line"></span><br><span class="line"># 确认 hexo 已经更新</span><br><span class="line">hexo -v</span><br></pre></td></tr></table></figure></div>
]]></content>
<tags>
<tag>个人博客搭建</tag>
<tag>教程</tag>
<tag>Hexo</tag>
</tags>
</entry>
<entry>
<title>C++鼠标连点器</title>
<url>/2023/02/04/C-%E9%BC%A0%E6%A0%87%E8%BF%9E%E7%82%B9%E5%99%A8/</url>
<content><![CDATA[<p>前几天LOL PBE 出现了BUG,可以无限刷宝箱。但是要鼠标连续4下才能刷到。于是我就想到用鼠标连点器来自动刷。<br><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202302041712343.png"
></p>
<p>经过几次搜索,我在知乎上找到了能够自己设定鼠标坐标的连点器,我稍微修改了一下。</p>
<p>最后,我也成功刷了1W多个宝箱。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202302041718546.png"
></p>
<p>下面是原代码</p>
<div class="highlight-container" data-rel="C++"><figure class="iseeu highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"iostream"</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"conio.h"</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"ctime"</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"vector"</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"string"</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">"windows.h"</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">set_cursor</span><span class="params">(<span class="type">bool</span> hide)</span></span>{</span><br><span class="line"> HANDLE handle = <span class="built_in">GetStdHandle</span>(STD_OUTPUT_HANDLE);</span><br><span class="line"> CONSOLE_CURSOR_INFO CursorInfo;</span><br><span class="line"> <span class="built_in">GetConsoleCursorInfo</span>(handle, &CursorInfo);</span><br><span class="line"> CursorInfo.bVisible = hide;</span><br><span class="line"> <span class="built_in">SetConsoleCursorInfo</span>(handle, &CursorInfo);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">gotoxy</span><span class="params">(<span class="type">int</span> x, <span class="type">int</span> y)</span></span>{</span><br><span class="line"> COORD c = {(SHORT)x, (SHORT)y};</span><br><span class="line"> <span class="built_in">SetConsoleCursorPosition</span>(<span class="built_in">GetStdHandle</span>(STD_OUTPUT_HANDLE), c);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">setmode</span><span class="params">()</span></span>{</span><br><span class="line"> HANDLE hStdin = <span class="built_in">GetStdHandle</span>(STD_INPUT_HANDLE);</span><br><span class="line"> DWORD mode;</span><br><span class="line"> <span class="built_in">GetConsoleMode</span>(hStdin, &mode);</span><br><span class="line"> mode &= ~ENABLE_QUICK_EDIT_MODE;</span><br><span class="line"> <span class="built_in">SetConsoleMode</span>(hStdin, mode);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Click</span>{</span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line"> <span class="type">int</span> x, y;</span><br><span class="line"> <span class="type">int</span> delay;</span><br><span class="line"> <span class="type">int</span> button_down, button_up;</span><br><span class="line"> std::string msg;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">setmode</span>();</span><br><span class="line"> std::cout << <span class="string">"欢迎使用鼠标连点器。\n\n"</span> << std::endl;</span><br><span class="line"> _ReStart_:</span><br><span class="line"> std::<span class="built_in">system</span>(<span class="string">"mode con cols=40 lines=15"</span>);</span><br><span class="line"> <span class="built_in">set_cursor</span>(<span class="literal">true</span>);</span><br><span class="line"> <span class="built_in">SetWindowPos</span>(<span class="built_in">GetConsoleWindow</span>(), HWND_TOPMOST, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, SWP_NOMOVE | SWP_NOSIZE);</span><br><span class="line"> std::cout << <span class="string">"请选择模式:\n"</span> << <span class="string">" 1.点击位置为鼠标指针,鼠标左/右键点击\n"</span> << <span class="string">" 2.点击位置固定循环,鼠标左/右键点击\n"</span> << <span class="string">" 0.退出\n"</span>;</span><br><span class="line"> <span class="type">int</span> ch = _getch();</span><br><span class="line"> <span class="keyword">while</span>(ch < <span class="string">'0'</span> || ch > <span class="string">'2'</span>) ch = _getch();</span><br><span class="line"> std::<span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="built_in">set_cursor</span>(<span class="literal">false</span>);</span><br><span class="line"> <span class="keyword">if</span> (ch == <span class="string">'1'</span>){</span><br><span class="line"> <span class="built_in">set_cursor</span>(<span class="literal">true</span>);</span><br><span class="line"> std::cout << <span class="string">"配置:"</span>;</span><br><span class="line"> std::cout << <span class="string">"请输入每秒钟的点击次数(1—1000):"</span> << std::endl;</span><br><span class="line"> <span class="type">int</span> spd;</span><br><span class="line"> std::cin >> spd;</span><br><span class="line"> std::cout << <span class="string">"\n请选择点击的键(0左键,1右键):"</span> << std::endl;</span><br><span class="line"> ch = _getch();</span><br><span class="line"> <span class="keyword">while</span>(ch < <span class="string">'0'</span> || ch > <span class="string">'1'</span>) ch = _getch();</span><br><span class="line"> <span class="type">int</span> CLICK_BUTTON_DOWN = (ch == <span class="string">'0'</span> ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN);</span><br><span class="line"> <span class="type">int</span> CLICK_BUTTON_UP = (ch == <span class="string">'0'</span> ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP);</span><br><span class="line"> std::<span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="type">int</span> cont = <span class="literal">true</span>, lst_tim = <span class="built_in">clock</span>();</span><br><span class="line"> <span class="built_in">set_cursor</span>(<span class="literal">false</span>);</span><br><span class="line"> <span class="keyword">while</span>(<span class="literal">true</span>){</span><br><span class="line"> <span class="built_in">gotoxy</span>(<span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> std::string t;</span><br><span class="line"> std::string y;</span><br><span class="line"> t=cont ? <span class="string">"运行中"</span> : <span class="string">"已暂停"</span>;</span><br><span class="line"> y=cont ? <span class="string">"暂停"</span> : <span class="string">"继续"</span>;</span><br><span class="line"> std::cout << <span class="string">"\n\n连点器"</span> << t << std::endl;</span><br><span class="line"> std::cout << <span class="string">"\n速度:"</span> << spd << <span class="string">"次/秒"</span> << std:: endl;</span><br><span class="line"> std::cout << <span class="string">" \n空格键:"</span> << y << std::endl;</span><br><span class="line"> std::cout << <span class="string">" \nEsc键:退出"</span> << std::endl;</span><br><span class="line"> <span class="built_in">SetWindowPos</span>(<span class="built_in">GetConsoleWindow</span>(), HWND_TOPMOST, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, SWP_NOMOVE | SWP_NOSIZE); <span class="comment">// 窗口置顶</span></span><br><span class="line"> <span class="keyword">if</span>(_kbhit()){</span><br><span class="line"> <span class="type">int</span> ch = _getch();</span><br><span class="line"> <span class="keyword">if</span>(ch == <span class="number">27</span>){</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(ch == <span class="string">' '</span>){</span><br><span class="line"> cont = !cont;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">if</span>(cont)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(<span class="built_in">clock</span>() - lst_tim >= <span class="number">1.0</span> / spd * CLOCKS_PER_SEC){</span><br><span class="line"> lst_tim = <span class="built_in">clock</span>();</span><br><span class="line"> POINT pt;</span><br><span class="line"> <span class="built_in">GetCursorPos</span>(&pt);</span><br><span class="line"> <span class="built_in">mouse_event</span>(CLICK_BUTTON_DOWN, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> <span class="built_in">mouse_event</span>(CLICK_BUTTON_UP, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(ch == <span class="string">'2'</span>){</span><br><span class="line"> std::cout << <span class="string">"请输入您要点击的位置个数:"</span> << std::endl;</span><br><span class="line"> <span class="type">int</span> times;</span><br><span class="line"> std::cin >> times;</span><br><span class="line"> std::vector<Click> ps;</span><br><span class="line"> <span class="built_in">set_cursor</span>(<span class="literal">true</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">1</span>; i <= times; i++){</span><br><span class="line"> std::<span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> std::cout << <span class="string">"将鼠标移动到第"</span> << i << <span class="string">"个位置上后按下空格:"</span> << std::endl;</span><br><span class="line"> <span class="keyword">while</span> (_getch() != <span class="string">' '</span>) {}</span><br><span class="line"> POINT p;</span><br><span class="line"> <span class="built_in">GetCursorPos</span>(&p);</span><br><span class="line"> ps.<span class="built_in">push_back</span>({p.x, p.y, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="string">""</span>});</span><br><span class="line"> std::cout << <span class="string">"\n需要按下的键(0左键,1右键):"</span> << std::endl;</span><br><span class="line"> <span class="type">char</span> ch = _getch();</span><br><span class="line"> <span class="keyword">while</span> (ch < <span class="string">'0'</span> || ch > <span class="string">'1'</span>) ch = _getch();</span><br><span class="line"> ps.<span class="built_in">back</span>().button_down = (ch == <span class="string">'0'</span> ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN);</span><br><span class="line"> ps.<span class="built_in">back</span>().button_up = (ch == <span class="string">'0'</span> ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP);</span><br><span class="line"> std::cout << <span class="string">"\n在上一次点击后需要等待多少毫秒:"</span> << std::endl;</span><br><span class="line"> <span class="type">int</span> delay;</span><br><span class="line"> std::cin >> delay;</span><br><span class="line"> ps.<span class="built_in">back</span>().delay = delay;</span><br><span class="line"> std::cout << <span class="string">"\n附加描述(可不填):"</span> << std::endl;</span><br><span class="line"> <span class="type">char</span> msg[<span class="number">10000</span>];</span><br><span class="line"> <span class="built_in">gets</span>(msg);</span><br><span class="line"> <span class="built_in">gets</span>(msg);</span><br><span class="line"> ps.<span class="built_in">back</span>().msg = msg;</span><br><span class="line"> }</span><br><span class="line"> <span class="type">int</span> cont = <span class="literal">true</span>;</span><br><span class="line"> <span class="type">int</span> now = <span class="number">0</span>;</span><br><span class="line"> <span class="type">int</span> lst_tim = <span class="built_in">clock</span>();</span><br><span class="line"> std::<span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> <span class="built_in">set_cursor</span>(<span class="literal">false</span>);</span><br><span class="line"> <span class="keyword">while</span>(<span class="literal">true</span>){</span><br><span class="line"> <span class="built_in">gotoxy</span>(<span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> std::string e;</span><br><span class="line"> std::string r;</span><br><span class="line"> e=cont ? <span class="string">"运行中"</span> : <span class="string">"已暂停"</span>;</span><br><span class="line"> r=cont ? <span class="string">"暂停"</span> : <span class="string">"继续"</span>;</span><br><span class="line"> std::cout << <span class="string">"连点器"</span> << e << std::endl;</span><br><span class="line"> std::cout << <span class="string">"当前位置描述:"</span> << ps[now].msg.<span class="built_in">c_str</span>() << std::endl;</span><br><span class="line"> std::cout << <span class="string">"需要等待:"</span> << ps[now].delay << <span class="string">"毫秒"</span><< std::endl;</span><br><span class="line"> std::cout << <span class="string">"点击按键:"</span> << (ps[now].button_down == MOUSEEVENTF_LEFTDOWN ? <span class="string">"右"</span> : <span class="string">"左"</span> )<< <span class="string">"键\n"</span> << std::endl;</span><br><span class="line"> std::cout << <span class="string">" 空格键:"</span> << r << std::endl;</span><br><span class="line"> std::cout << <span class="string">" Esc键:退出"</span> << std::endl;</span><br><span class="line"> <span class="built_in">SetWindowPos</span>(<span class="built_in">GetConsoleWindow</span>(), HWND_TOPMOST, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, SWP_NOMOVE | SWP_NOSIZE); <span class="comment">// 窗口置顶</span></span><br><span class="line"> <span class="keyword">if</span>(_kbhit()){</span><br><span class="line"> <span class="type">int</span> ch = _getch();</span><br><span class="line"> <span class="keyword">if</span>(ch == <span class="number">27</span>){</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> } <span class="keyword">else</span> <span class="keyword">if</span>(ch == <span class="string">' '</span>){</span><br><span class="line"> cont = !cont;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span> {</span><br><span class="line"> <span class="keyword">if</span>(cont){</span><br><span class="line"> <span class="keyword">if</span>(<span class="built_in">clock</span>() - lst_tim > ps[now].delay){</span><br><span class="line"> lst_tim = <span class="built_in">clock</span>();</span><br><span class="line"> POINT pt;</span><br><span class="line"> <span class="built_in">GetCursorPos</span>(&pt);</span><br><span class="line"> <span class="built_in">SetCursorPos</span>(ps[now].x, ps[now].y);</span><br><span class="line"> <span class="built_in">mouse_event</span>(ps[now].button_down, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> <span class="built_in">mouse_event</span>(ps[now].button_up, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> <span class="built_in">SetCursorPos</span>(pt.x, pt.y);</span><br><span class="line"> <span class="keyword">if</span>(now + <span class="number">1</span> == (<span class="type">int</span>)ps.<span class="built_in">size</span>()) now = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> now = now + <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> std::<span class="built_in">system</span>(<span class="string">"cls"</span>);</span><br><span class="line"> std::cout << <span class="string">"欢迎回来!\n\n"</span> <<std::endl;</span><br><span class="line"> <span class="keyword">goto</span> _ReStart_;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
]]></content>
<tags>
<tag>C++</tag>
<tag>鼠标连点器</tag>
</tags>
</entry>
<entry>
<title>VS Code 配置 C/C++编译环境</title>
<url>/2024/04/18/VS%20Code%20%E9%85%8D%E7%BD%AE%20C%E5%92%8CC++%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83/</url>
<content><![CDATA[<h1 id="一-MinGW下载"><a href="#一-MinGW下载" class="headerlink" title="一 . MinGW下载"></a>一 . MinGW下载</h1><p>下载地址:<a class="link" href="https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/" >https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/</a></p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041306602.png"
></p>
<p>选择红色框里的<code>x86_64-posix-seh</code>。</p>
<p>下载后打开解压到你想要的位置。</p>
<h1 id="二-配置系统环境"><a href="#二-配置系统环境" class="headerlink" title="二. 配置系统环境"></a>二. 配置系统环境</h1><ol>
<li><p>打开<code>编辑系统变量</code> ;</p>
</li>
<li><p>打开<code>系统变量</code>里的<code>Path</code>;</p>
</li>
<li><p>新建变量, 将刚才解压后的MinGW里<code>Bin</code>文件夹的<code>绝对路径</code>添加进去; </p>
</li>
<li><p>保存并退出。</p>
</li>
</ol>
<h1 id="三-VS-Code,插件下载"><a href="#三-VS-Code,插件下载" class="headerlink" title="三. VS Code,插件下载"></a>三. VS Code,插件下载</h1><ol>
<li><p>下载VS Code本体软件</p>
</li>
<li><p>安装<code>C/C++</code>插件</p>
</li>
<li><p>安装好插件后重新打开VS Code.</p>
</li>
</ol>
<h1 id="四-配置文件"><a href="#四-配置文件" class="headerlink" title="四. 配置文件"></a>四. 配置文件</h1><h2 id="1-tasks-json-launch-json配置"><a href="#1-tasks-json-launch-json配置" class="headerlink" title="1. tasks.json, launch.json配置"></a>1. tasks.json, launch.json配置</h2><p><strong>注意: 先配置<code>tasks.json</code> , 再配置<code>launch.json</code>.</strong></p>
<p>以自己实际情况, 按照以下配置代码里的注释来配置.</p>
<div class="highlight-container" data-rel="Json"><figure class="iseeu highlight json"><table><tr><td class="code"><pre><span class="line"><span class="comment">//tasks.json</span></span><br><span class="line"><span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"tasks"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"cppbuild"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"label"</span><span class="punctuation">:</span> <span class="string">"C/C++ Debug"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"command"</span><span class="punctuation">:</span> <span class="string">"D:/MinGW/mingw64/bin/gcc.exe"</span><span class="punctuation">,</span> <span class="comment">// gcc.exe的路径</span></span><br><span class="line"> <span class="attr">"command"</span><span class="punctuation">:</span> <span class="string">"D:/MinGW/mingw64/bin/g++.exe"</span><span class="punctuation">,</span> <span class="comment">//g++.exe的路径</span></span><br><span class="line"> <span class="attr">"args"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="comment">// 输入给终端的参数</span></span><br><span class="line"> <span class="string">"-fdiagnostics-color=always"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">""</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">"-g"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">"${file}"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">"-o"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="string">"${fileDirname}/bin/${fileBasenameNoExtension}.exe"</span><span class="punctuation">,</span><span class="comment">//生成exe文件的路径(不支持中文命名C/C++文件)</span></span><br><span class="line"> <span class="comment">//"${fileDirname}/bin/test.exe",//生成exe文件的路径(支持中文命名C/C++文件)</span></span><br><span class="line"> <span class="string">"-fexec-charset=GBK"</span><span class="punctuation">,</span><span class="comment">//编码格式(按照GBK格式输出可以显示中文字符)</span></span><br><span class="line"> <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"options"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"cwd"</span><span class="punctuation">:</span> <span class="string">"${fileDirname}"</span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"problemMatcher"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="string">"$gcc"</span></span><br><span class="line"> <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"group"</span><span class="punctuation">:</span> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"kind"</span><span class="punctuation">:</span> <span class="string">"build"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"isDefault"</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span></span><br><span class="line"> <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"detail"</span><span class="punctuation">:</span> <span class="string">"Task generated by Debugger."</span></span><br><span class="line"> <span class="punctuation">}</span></span><br><span class="line"> <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"version"</span><span class="punctuation">:</span> <span class="string">"2.0.0"</span></span><br><span class="line"><span class="punctuation">}</span></span><br></pre></td></tr></table></figure></div>
<div class="highlight-container" data-rel="Json"><figure class="iseeu highlight json"><table><tr><td class="code"><pre><span class="line"><span class="comment">//launch.json</span></span><br><span class="line"><span class="punctuation">{</span></span><br><span class="line"> <span class="comment">// Use IntelliSense to learn about possible attributes.</span></span><br><span class="line"> <span class="comment">// Hover to view descriptions of existing attributes.</span></span><br><span class="line"> <span class="comment">// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387</span></span><br><span class="line"> <span class="attr">"version"</span><span class="punctuation">:</span> <span class="string">"0.2.0"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"configurations"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> </span><br><span class="line"> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"name"</span><span class="punctuation">:</span> <span class="string">"(gdb) Launch"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"preLaunchTask"</span><span class="punctuation">:</span> <span class="string">"C/C++ Debug"</span><span class="punctuation">,</span><span class="comment">//调试前执行的任务,就是之前配置的tasks.json中的label字段</span></span><br><span class="line"> <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"cppdbg"</span><span class="punctuation">,</span><span class="comment">//配置类型,只能为cppdbg</span></span><br><span class="line"> <span class="attr">"request"</span><span class="punctuation">:</span> <span class="string">"launch"</span><span class="punctuation">,</span><span class="comment">//请求配置类型,可以为launch(启动)或attach(附加)</span></span><br><span class="line"> <span class="attr">"program"</span><span class="punctuation">:</span> <span class="string">"${fileDirname}/bin/${fileBasenameNoExtension}.exe"</span><span class="punctuation">,</span><span class="comment">//调试程序的路径名称(不支持中文命名C/C++文件)</span></span><br><span class="line"> <span class="comment">//"program": "${fileDirname}/bin/test.exe",//调试程序的路径名称(支持中文命名C/C++文件)</span></span><br><span class="line"> <span class="attr">"args"</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="punctuation">]</span><span class="punctuation">,</span><span class="comment">//调试传递参数</span></span><br><span class="line"> <span class="attr">"stopAtEntry"</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">false</span></span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"cwd"</span><span class="punctuation">:</span> <span class="string">"${workspaceFolder}"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"environment"</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"externalConsole"</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span><span class="comment">//true显示外置的控制台窗口,false显示内置终端</span></span><br><span class="line"> <span class="attr">"MIMode"</span><span class="punctuation">:</span> <span class="string">"gdb"</span><span class="punctuation">,</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// gdb.exe的路径</span></span><br><span class="line"> <span class="attr">"miDebuggerPath"</span><span class="punctuation">:</span> <span class="string">"D:/MinGW/mingw64/bin/gdb.exe"</span><span class="punctuation">,</span></span><br><span class="line"> </span><br><span class="line"> <span class="attr">"setupCommands"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line"> <span class="punctuation">{</span></span><br><span class="line"> <span class="attr">"description"</span><span class="punctuation">:</span> <span class="string">"Enable pretty-printing for gdb"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"text"</span><span class="punctuation">:</span> <span class="string">"-enable-pretty-printing"</span><span class="punctuation">,</span></span><br><span class="line"> <span class="attr">"ignoreFailures"</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span></span><br><span class="line"> <span class="punctuation">}</span></span><br><span class="line"> <span class="punctuation">]</span></span><br><span class="line"> <span class="punctuation">}</span></span><br><span class="line"> <span class="punctuation">]</span></span><br><span class="line"><span class="punctuation">}</span></span><br></pre></td></tr></table></figure></div>
<h2 id="2-C-C-插件配置"><a href="#2-C-C-插件配置" class="headerlink" title="2. C/C++插件配置"></a>2. C/C++插件配置</h2><ol>
<li>按住Ctrl+Shift+p , 搜索找到<code>C/C++: Edit Configurations (Ul)</code>并打开.</li>
<li>找到<code>编译器路径</code>选项, 选择MinGW里Bin夹的<code>g++.exe</code>.<img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/C_Plug_Config.png"
></li>
<li>重新打开VS Code.</li>
</ol>
<p>至此已完成VS Code配置C/C++编译环境. </p>
]]></content>
<tags>
<tag>VS</tag>
<tag>Code</tag>
</tags>
</entry>
<entry>
<title>Linux访问Github设置</title>
<url>/2024/04/15/Linux%E8%AE%BF%E9%97%AEGithub%E8%AE%BE%E7%BD%AE/</url>
<content><![CDATA[<p>为方便以后每次重新设置Linux. 特此写下本文来记录配置Linux访问Github的经验. </p>
<p>还没配置Linux之前,每次下载Github里的内容时显示 类似</p>
<p>fatal: 无法访问 ‘’<a class="link" href="https://github.com/''.............%EF%BC%9AGnuTLS" >https://github.com/''.............:GnuTLS</a> recv error (-110): The TLS connection was non-properly terminated. Failed during: /usr/bin/git fetch –force origin</p>
<p>这种错误提示. 以下为解决方案.</p>
<h1 id="1-sudo-vim-etc-hosts"><a href="#1-sudo-vim-etc-hosts" class="headerlink" title="1. sudo vim /etc/hosts"></a>1. sudo vim /etc/hosts</h1><h1 id="2-将以下内容输入到hosts并保存退出"><a href="#2-将以下内容输入到hosts并保存退出" class="headerlink" title="2. 将以下内容输入到hosts并保存退出."></a>2. 将以下内容输入到hosts并保存退出.</h1><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line"># GitHub Start </span><br><span class="line">140.82.114.3 github.com</span><br><span class="line">140.82.113.3 github.com</span><br><span class="line">140.82.114.20 gist.github.com</span><br><span class="line">151.101.184.133 assets-cdn.github.com</span><br><span class="line">151.101.184.133 raw.githubusercontent.com</span><br><span class="line">151.101.184.133 gist.githubusercontent.com</span><br><span class="line">151.101.184.133 cloud.githubusercontent.com</span><br><span class="line">151.101.184.133 camo.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars0.githubusercontent.com</span><br><span class="line">199.232.68.133 avatars0.githubusercontent.com</span><br><span class="line">199.232.28.133 avatars1.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars1.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars2.githubusercontent.com</span><br><span class="line">199.232.28.133 avatars2.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars3.githubusercontent.com</span><br><span class="line">199.232.68.133 avatars3.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars4.githubusercontent.com</span><br><span class="line">199.232.68.133 avatars4.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars5.githubusercontent.com</span><br><span class="line">199.232.68.133 avatars5.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars6.githubusercontent.com</span><br><span class="line">199.232.68.133 avatars6.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars7.githubusercontent.com</span><br><span class="line">199.232.68.133 avatars7.githubusercontent.com</span><br><span class="line">151.101.184.133 avatars8.githubusercontent.com</span><br><span class="line">199.232.68.133 avatars8.githubusercontent.com</span><br><span class="line"># GitHub End</span><br></pre></td></tr></table></figure></div>
<p>测试访问Github, 已成功访问.</p>
]]></content>
<tags>
<tag>Linux</tag>
<tag>Github</tag>
</tags>
</entry>
<entry>
<title>Windows+CLion+OpenCV配置</title>
<url>/2023/04/04/Windows+CLion+OpenCV%E9%85%8D%E7%BD%AE/</url>
<content><![CDATA[<h1 id="下载OpenCV"><a href="#下载OpenCV" class="headerlink" title="下载OpenCV"></a>下载OpenCV</h1><p>下载地址:<a class="link" href="https://opencv.org/releases/" >https://opencv.org/releases/</a></p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041302762.png"
></p>
<p>下载后打开压缩到你想要的位置。</p>
<h1 id="下载CMake"><a href="#下载CMake" class="headerlink" title="下载CMake"></a>下载CMake</h1><p>下载地址:<a class="link" href="https://cmake.org/download/" >https://cmake.org/download/</a></p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041304285.png"
></p>
<p><strong>安装时选择为所有用户添加环境变量</strong></p>
<h1 id="下载MinGW"><a href="#下载MinGW" class="headerlink" title="下载MinGW"></a>下载MinGW</h1><p>下载地址:<a class="link" href="https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/" >https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/</a></p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041306602.png"
></p>
<p>注意:选择红色框里的<code>x86_64-posix-seh</code> 的MinGW。</p>
<p>下载后打开解压到你想要的位置。</p>
<h1 id="生成OpenCV的makefile文件"><a href="#生成OpenCV的makefile文件" class="headerlink" title="生成OpenCV的makefile文件"></a>生成OpenCV的makefile文件</h1><p> 安装好以上软件后,打开<code>cmake-gui</code></p>
<p> 点击<code>Browse Source</code>选择选择 <code>opencv</code> 下的 <code>sources</code>文件夹</p>
<p> 点击<code>Browse Build</code>选择选择 <code>opencv</code> 下的 <code>mingw_build</code>文件夹</p>
<p> 如果OpenCV文件里没有mingw_build,就新建一个mingw_build文件夹</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041334483.png"
></p>
<p> 点击Configure,指定编译器</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041319119.png"
></p>
<p> 分别选择刚刚下载的posix版本MinGW-W64下的gcc和g++</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041321814.png"
></p>
<p>点击Finish,等待完成</p>
<p>如遇到一下问题,请打开下面的文件</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041323909.png"
></p>
<p>按照日志里的下载地址分别下载这三个文件并放入<code>/source/.cache/ffmpeg</code>中,使用<code>certutil -hashfile 文件名 MD5</code>获取每个文件的MD5,以<code>MD5-文件名</code>重新命名这三个文件。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041323786.png"
></p>
<p> 回到cmake-gui,重新点击Configure,若无其他报错则点击Generate生成Makefile文件。</p>
<h1 id="编译"><a href="#编译" class="headerlink" title="编译"></a>编译</h1><p> 打开命令行进入<code>mingw-build</code>文件夹,使用<code>mingw32-make -j8</code>编译(8为核心数,请自行调整),编译速度大概10分钟左右。</p>
<p> 编译成功后,使用<code>mingw32-make install</code>命令将编译生成的文件整合到<code>opencv/mingw_build/install</code>目录中</p>
<h1 id="配置环境变量"><a href="#配置环境变量" class="headerlink" title="配置环境变量"></a>配置环境变量</h1><p> 配置环境变量,将<code>opencv/mingw_build/install/x64/mingw/bin</code>加入环境变量中的path中。</p>
<h1 id="在Clion项目中使用OpenCV"><a href="#在Clion项目中使用OpenCV" class="headerlink" title="在Clion项目中使用OpenCV"></a>在Clion项目中使用OpenCV</h1><p> 新建项目,编辑<code>CMakeLists.txt</code></p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">cmake_minimum_required(VERSION 3.25)</span><br><span class="line">project(OPenCVdebug)</span><br><span class="line"></span><br><span class="line">set(CMAKE_CXX_STANDARD 17)</span><br><span class="line"></span><br><span class="line"># 设置OpenCV目录</span><br><span class="line">set(OpenCV_DIR D:/OpenCV/opencv/mingw_build/install)</span><br><span class="line"></span><br><span class="line"># 搜索OpenCV目录</span><br><span class="line">find_package(OpenCV REQUIRED)</span><br><span class="line">include_directories("D:/OpenCV/opencv/build/include")</span><br><span class="line">add_executable(OPenCVdebug main.cpp)</span><br><span class="line"></span><br><span class="line"># 链接OpenCV库文件</span><br><span class="line">target_link_libraries(OPenCVdebug ${OpenCV_LIBS})</span><br><span class="line"></span><br></pre></td></tr></table></figure></div>
<p>里面的OPenCVdebug换成你自己项目的名称。有关文件路径也换成你的。</p>
<p> 编辑<code>main.cpp</code></p>
<div class="highlight-container" data-rel="C++"><figure class="iseeu highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><opencv2/highgui/highgui.hpp></span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> cv;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> Mat img = <span class="built_in">imread</span>(<span class="string">"test.jpg"</span>);</span><br><span class="line"> <span class="built_in">namedWindow</span>(<span class="string">"test"</span>, WINDOW_AUTOSIZE);</span><br><span class="line"> <span class="built_in">imshow</span>(<span class="string">"test"</span>, img);</span><br><span class="line"> <span class="built_in">waitKey</span>();</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<p> 编译运行</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304041330181.png"
></p>
<p>本文转自<a class="link" href="https://www.robotsfan.com/" >范子琦的博客</a></p>
]]></content>
<tags>
<tag>CLion</tag>
<tag>OpenCV</tag>
</tags>
</entry>
<entry>
<title>Windows+CLion+cULR 配置</title>
<url>/2023/04/05/Windows+CLion+cURL%E9%85%8D%E7%BD%AE/</url>
<content><![CDATA[<h1 id="下载cURL"><a href="#下载cURL" class="headerlink" title="下载cURL"></a>下载cURL</h1><p>下载地址: <a class="link" href="https://curl.se/download.html#Win64" >https://curl.se/download.html#Win64</a><br><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304051111594.png"
><br>下载打开后选择自己想要的解压地址。</p>
<h1 id="配置环境变量"><a href="#配置环境变量" class="headerlink" title="配置环境变量"></a>配置环境变量</h1><p>将cURL文件里的<code>bin</code>加入环境变量中的path中。</p>
<h1 id="在CLion中使用cURL"><a href="#在CLion中使用cURL" class="headerlink" title="在CLion中使用cURL"></a>在CLion中使用cURL</h1><p>新建项目,编辑<code>CMakeLists.txt</code></p>
<p>将以下代码添加进去。</p>
<div class="highlight-container" data-rel="Cmake"><figure class="iseeu highlight cmake"><table><tr><td class="code"><pre><span class="line"><span class="keyword">set</span>(CURL_LIBRARY)</span><br><span class="line"><span class="keyword">find_package</span>(CURL REQUIRED)</span><br><span class="line"><span class="keyword">include_directories</span>(<span class="variable">${CURL_INCLUDE_DIR}</span>)</span><br><span class="line"><span class="keyword">target_link_libraries</span>(your_project <span class="variable">${CURL_LIBRARY}</span>)</span><br></pre></td></tr></table></figure></div>
<p>your_project换成你项目的名称。</p>
<h1 id="在CLion终端里使用cURL"><a href="#在CLion终端里使用cURL" class="headerlink" title="在CLion终端里使用cURL"></a>在CLion终端里使用cURL</h1><p>打开<code>File -> settings -> Tools -> Terminal</code> ,在启动目录里添加cURL的<code>bin</code>文件路径。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304051122864.png"
></p>
<p>编译<code>main.cpp</code></p>
<div class="highlight-container" data-rel="C++"><figure class="iseeu highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><curl/curl.h></span></span></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"> CURL *curl;</span><br><span class="line"> CURLcode res;</span><br><span class="line"> std::string url = <span class="string">"www.bilibili.com"</span>;</span><br><span class="line"> curl = <span class="built_in">curl_easy_init</span>();</span><br><span class="line"> <span class="keyword">if</span>(curl) {</span><br><span class="line"> <span class="built_in">curl_easy_setopt</span>(curl, CURLOPT_URL, url.<span class="built_in">c_str</span>());</span><br><span class="line"> res = <span class="built_in">curl_easy_perform</span>(curl);</span><br><span class="line"> <span class="keyword">if</span>(res == CURLE_OK) {</span><br><span class="line"> std::cout << <span class="string">"Request successful!"</span> << std::endl;</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> std::cout << <span class="string">"Request failed: "</span> << <span class="built_in">curl_easy_strerror</span>(res) << std::endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">curl_easy_cleanup</span>(curl);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></div>
<p>如果curl库成功配置,则运行上述程序将于最后一行输出<code>Request successful!</code>,否则未成功配置。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304051131215.png"
></p>
<p>如果你打开Clion生成的可执行文件时显示如下错误</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202304051140830.png"
></p>
<p>就在CMakeLists.txt里添加以下代码</p>
<div class="highlight-container" data-rel="Cmake"><figure class="iseeu highlight cmake"><table><tr><td class="code"><pre><span class="line"><span class="keyword">set</span>(CMAKE_CXX_FLAGS <span class="string">"${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc"</span>)</span><br></pre></td></tr></table></figure></div>
<p>然后点击 <code>文件 --> 重新加载CMake项目</code> ,再次编译程序,就可以打开Clion生成的可执行文件了。</p>
]]></content>
<categories>
<category>CLion</category>
<category>cURL</category>
</categories>
<tags>
<tag>CLion</tag>
<tag>cURL</tag>
</tags>
</entry>
<entry>
<title>所有我能找到的CDN加速</title>
<url>/2022/10/18/%E6%89%80%E6%9C%89%E6%88%91%E8%83%BD%E6%89%BE%E5%88%B0%E7%9A%84CDN%E5%8A%A0%E9%80%9F/</url>
<content><![CDATA[<h1 id="前言:"><a href="#前言:" class="headerlink" title="前言:"></a>前言:</h1><p>建站后,我一直找图床,之后了解到 Github 也可以当成图床。但是 raw 在大陆的访问速度实在是太慢了,有时候还会访问超时。<br>最近找到了几个<strong>可以加速 Github,可在大陆用的免费</strong> CDN.</p>
<p><strong>npm+Github 搭建图床——<a class="link" href="https://amnesia-f.github.io/posts/npm/" >使用 npm 搭建图床教程</a></strong>.</p>
<p>下面是免费 CDN。</p>
<p><strong>1.jsdelivr</strong> <a class="link" href="https://www.jsdelivr.com/" >Jsdelivr 官网</a></p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">Ⅰ http://cdn.jsdelivr.net</span><br><span class="line">Ⅱ http://fastly.jsdelivr.net</span><br><span class="line">Ⅲ http://gcore.jsdelivr.net</span><br></pre></td></tr></table></figure></div>
<p><strong>2.cloudflare</strong></p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">http://cdnjs.cloudflare.com/</span><br></pre></td></tr></table></figure></div>
<p><strong>3.unpkg</strong></p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://www.unpkg.com/</span><br><span class="line">https://unpkg.zhimg.com (国内镜像)</span><br></pre></td></tr></table></figure></div>
<p><strong>4.BootCDN</strong></p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">https://www.bootcdn.cn/</span><br></pre></td></tr></table></figure></div>
]]></content>
<tags>
<tag>Hexo</tag>
<tag>CDN</tag>
</tags>
</entry>
<entry>
<title>搭建个人博客的保姆级教程</title>
<url>/2022/10/12/%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E7%9A%84%E6%96%B9%E6%B3%95/</url>
<content><![CDATA[<p>这篇文章在 2 个教程基础上做了部分修改以成功达成搭建个人博客网站的目的.教程 1</a> <a class="link" href="https://www.bilibili.com/video/BV1mU4y1j72n?p=5&share_source=copy_web&vd_source=b7b545c609b8f4639b9ecb9b5178bdac" >教程 2</a></p>
<p>本文将使用<strong>Hexo</strong>框架和<strong>GitHub</strong>来创建属于自己的博客。</p>
<h2 id="一:搭建博客需要的工具"><a href="#一:搭建博客需要的工具" class="headerlink" title="一:搭建博客需要的工具"></a>一:搭建博客需要的工具</h2><p>1:注册一个 GitHub 账号。<strong>注意!要记住你注册时填的邮箱和你的用户名!</strong></p>
<p><a class="link" href="https://www.bilibili.com/read/cv5107169" >GitHub 账号注册详细流程</a></p>
<p>2.下载 Node.js 和 npm 软件(npm 包含其 node.js 里)。</p>
<p><a class="link" href="https://nodejs.org/en/" >Node.js 官网</a> </p>
<p><strong>注意!版本尽量选LTS,防止后面无法部署。</strong></p>
<p>3.下载 Git 软件。</p>
<p><a class="link" href="https://git-scm.com/" > Git 官网</a></p>
<p>Ⅰ:安装好 Git 和 Node.js 后打开 CMD 输入一下命令来检查是否安装成功。若出现类似 v12.19.0 这种版本号则说明安装成功。</p>
<p>检查 Node.js</p>
<div class="highlight-container" data-rel="Powershell"><figure class="iseeu highlight powershell"><table><tr><td class="code"><pre><span class="line">node <span class="literal">-v</span></span><br></pre></td></tr></table></figure></div>
<p>检查npm</p>
<div class="highlight-container" data-rel="Powershell"><figure class="iseeu highlight powershell"><table><tr><td class="code"><pre><span class="line">npm <span class="literal">-v</span></span><br></pre></td></tr></table></figure></div>
<p>检查 Git</p>
<div class="highlight-container" data-rel="Powershell"><figure class="iseeu highlight powershell"><table><tr><td class="code"><pre><span class="line">git <span class="literal">--version</span></span><br></pre></td></tr></table></figure></div>
<p>Ⅱ:安装淘宝镜像并下载 Hexo。</p>
<p>(用淘宝镜像是为了能够顺利下载安装所有必需程序。)</p>
<p>1.安装淘宝镜像</p>
<div class="highlight-container" data-rel="Powershell"><figure class="iseeu highlight powershell"><table><tr><td class="code"><pre><span class="line">npm install <span class="literal">-g</span> cnpm <span class="literal">--registry</span>=https://registry.npm.taobao.org</span><br></pre></td></tr></table></figure></div>
<p>2.下载并安装 Hexo</p>
<div class="highlight-container" data-rel="Powershell"><figure class="iseeu highlight powershell"><table><tr><td class="code"><pre><span class="line">cnpm install <span class="literal">-g</span> hexo<span class="literal">-cli</span></span><br></pre></td></tr></table></figure></div>
<p>3.检查是否成功安装 Hexo</p>
<div class="highlight-container" data-rel="Powershell"><figure class="iseeu highlight powershell"><table><tr><td class="code"><pre><span class="line">hexo <span class="literal">-v</span></span><br></pre></td></tr></table></figure></div>
<p>该代码输出结果大致如下图所示。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182046614.png"
alt="1.png"
></p>
<h2 id="二:-创建-GitHub-仓库。"><a href="#二:-创建-GitHub-仓库。" class="headerlink" title="二: 创建 GitHub 仓库。"></a>二: 创建 GitHub 仓库。</h2><p>1.按照图片进入仓库。进去后点写着 New 的绿色按钮。<img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182047308.jpg"
alt="2.png"
></p>
<p>2.点击按钮进入到下图所示界面,按图设置。<strong>Repository name 那里一定要按照下面给出来的格式来填,yourname 换成你的 Github 名字</strong>然后点击 Create repository。</p>
<div class="highlight-container" data-rel="Powershell"><figure class="iseeu highlight powershell"><table><tr><td class="code"><pre><span class="line">yourname.github.io</span><br></pre></td></tr></table></figure></div>
<h1 id=""><a href="#" class="headerlink" title=""></a><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182047870.jpg"
alt="3.png"
></h1><h2 id="三:生成-SSH-Keys。"><a href="#三:生成-SSH-Keys。" class="headerlink" title="三:生成 SSH Keys。"></a><strong>三:</strong>生成 SSH Keys。</h2><p>1.创建一个新文件夹来放你的博客文件。</p>
<p>2.在你的博客文件夹里右击鼠标选<strong>Git Bash Here</strong>。</p>
<p>3.输入下面代码。</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">ssh-keygen -t rsa -C "你注册GitHub 时用的邮箱地址"</span><br></pre></td></tr></table></figure></div>
<p>然后慢慢地按 4 次回车。结果如下图所示。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182047702.png"
alt="4.png"
></p>
<p>4.在 <strong>Users/用户名/下找到 .ssh文件夹</strong>进入,打开 *<em>id_rsa.pub*</em> 文件(可以使用记事本,Notepad++或 VS Code 等软件打开),并全部复制里面内容。</p>
<p>5.打开 GitHub,添加新的 SSH Key。步骤如下:</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182048286.png"
alt="5.png"
></p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182048776.png"
alt="6.png"
></p>
<p>6.在 Git Bash 中输入代码测试 ssh 是否绑定成功</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">ssh -T [email protected]</span><br></pre></td></tr></table></figure></div>
<p>PS:如果一直显示ssh: connect to host github.com port 22: Connection refused。就点击查看 <a class="link" href="https://www.cnblogs.com/Archer314/p/14641310.html" >教程</a></p>
<h2 id="四:本地生成博客内容"><a href="#四:本地生成博客内容" class="headerlink" title="四:本地生成博客内容"></a><strong>四:</strong>本地生成博客内容</h2><h3 id="1-初始化。"><a href="#1-初始化。" class="headerlink" title="1. 初始化。"></a>1. 初始化。</h3><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">hexo init</span><br></pre></td></tr></table></figure></div>
<p>PS:输入该命令后可能出现连接超时(time out)的问题,如果出现了就再尝试几次。</p>
<p>成功生成的界面大致如下图:(当有 INFO Start blogging with Hexo!时标志成功生成。)<img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182048233.png"
alt="7.png"
></p>
<h3 id="2-浏览器中打开-http-localhost-4000-,即网页本地地址。"><a href="#2-浏览器中打开-http-localhost-4000-,即网页本地地址。" class="headerlink" title="2. 浏览器中打开 http://localhost:4000/ ,即网页本地地址。"></a>2. 浏览器中打开 <a class="link" href="http://localhost:4000/" >http://localhost:4000/ </a> ,即网页本地地址。</h3><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">hexo s</span><br></pre></td></tr></table></figure></div>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182049146.png"
alt="8.png"
></p>
<h3 id="3-修改配置文件"><a href="#3-修改配置文件" class="headerlink" title="3. 修改配置文件"></a>3. 修改配置文件</h3><p>P.S: 记得打开文件拓展名显示;</p>
<p> 本文使用的部署插件为hexo-deployer-git, 若使用其他部署插件,自行查找插件的配置文件编写方法。</p>
<p>① 到你的博客文件夹,用记事本或 VS Code 等软件打 开<strong>config.yml</strong>文件。</p>
<p>② 拉到最底下,记得<strong>切换成英文输入法</strong></p>
<p>下图里的代码要替换。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182049934.png"
alt="9.png"
></p>
<p>③ 把上图显示的代码替换成下面给出来的代码.(里面的 yourname 替换成你的 GitHub 名字)</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line"># Deployment</span><br><span class="line">## Docs: https://hexo.io/docs/one-command-deployment</span><br><span class="line">deploy:</span><br><span class="line">type: git</span><br><span class="line">repository: [email protected]:yourname/yourname.github.io.git</span><br><span class="line">branch: main</span><br></pre></td></tr></table></figure></div>
<p>④ 保存并退出文件。</p>
<h3 id="4-在博客文件夹打开-Git-Bash,安装-hexo-deployer-git自动部署发布插件。"><a href="#4-在博客文件夹打开-Git-Bash,安装-hexo-deployer-git自动部署发布插件。" class="headerlink" title="4. 在博客文件夹打开 Git Bash,安装 hexo-deployer-git自动部署发布插件。"></a>4. 在博客文件夹打开 Git Bash,安装 hexo-deployer-git自动部署发布插件。</h3><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">cnpm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure></div>
<p>安装好 hexo-deployer-git 自动部署发布插件大致如下图所示:</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182049704.jpg"
alt="10.png"
></p>
<h3 id="5-生成网页"><a href="#5-生成网页" class="headerlink" title="5. 生成网页"></a>5. 生成网页</h3><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">hexo g</span><br></pre></td></tr></table></figure></div>
<h3 id="6-部署博客"><a href="#6-部署博客" class="headerlink" title="6. 部署博客"></a>6. 部署博客</h3><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">hexo d</span><br></pre></td></tr></table></figure></div>
<p>前面安装 hexo-deployer-git 自动部署发布工具就是让这串代码可用, 如果没有安装该工具,则显示 ERROR Deployer not found : git</p>
<p>7.① 输入代码过了一会儿后,他会让你输入用户名和密码,先输入用户名。</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182050772.png"
alt="11.png"
></p>
<p>② 输入用户名后先别急着输入密码,打开 GitHub,生成一个新的<strong>token</strong>。步骤如下图:</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182050055.png"
alt="12.png"
></p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182050585.png"
alt="13.png"
></p>
<p>③ 将复制的<strong>token</strong>粘贴到密码中。(建议记录生成的 token,因为 token 只能显示一次。)</p>
<p><img
lazyload
src="/images/loading.svg"
data-src="https://gcore.jsdelivr.net/gh/Anivia-ad/photo_DEMO/img/202210182051434.png"
alt="14.png"
></p>
<p><strong>Congratulations, 你已经成功创建你的博客网站啦,这时候你就能访问你的网站啦。网站地址是:<a class="link" href="https://username.github.io/" >https://username.github.io </a></strong></p>
<p><strong>(username 换成你的 Github 名字)</strong></p>
]]></content>
<tags>
<tag>个人博客搭建</tag>
<tag>教程</tag>
<tag>Hexo</tag>
</tags>
</entry>
<entry>
<title>解决有关很久没更新后使用hexo s报错的问题</title>
<url>/2023/01/26/%E8%A7%A3%E5%86%B3%E6%9C%89%E5%85%B3%E5%BE%88%E4%B9%85%E6%B2%A1%E6%9B%B4%E6%96%B0%E5%90%8E%E4%BD%BF%E7%94%A8hexo%20s%E6%8A%A5%E9%94%99%E7%9A%84%E9%97%AE%E9%A2%98/</url>
<content><![CDATA[<p>因为个人原因很久没更新博客,前几天想着更新我的博客,写好后拿去Hexo s ,结果报错 。下面是报错结果:</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">PS D:\blog> hexo s</span><br><span class="line">INFO Validating config</span><br><span class="line">WARN Deprecated config detected: "external_link" with a Boolean value is deprecated. See https://hexo.io/docs/configuration for more details.</span><br><span class="line">ERROR Plugin load failed: hexo-butterfly-clock</span><br><span class="line">Error: ENOENT: no such file or directory, open 'D:\blog\node_modules\hexo-butterfly-clock' </span><br><span class="line">ERROR Plugin load failed: hexo-wordcount</span><br><span class="line">Error: ENOENT: no such file or directory, open 'D:\blog\node_modules\hexo-wordcount'</span><br><span class="line"></span><br><span class="line">INFO </span><br><span class="line"> ===================================================================</span><br><span class="line"></span><br><span class="line"> ##### # # ##### ##### ###### ##### ###### # # #</span><br><span class="line"> # # # # # # # # # # # # #</span><br><span class="line"> ##### # # # # ##### # # ##### # #</span><br><span class="line"> # # # # # # # ##### # # #</span><br><span class="line"> # # # # # # # # # # # #</span><br><span class="line"> ##### #### # # ###### # # # ###### #</span><br><span class="line"> </span><br><span class="line"> 4.4.0</span><br><span class="line"> ===================================================================</span><br><span class="line">Unhandled rejection TypeError: D:\blog\node_modules\hexo-theme-butterfly\layout\includes\widget\index.pug:33</span><br><span class="line"> 31| !=partial('includes/widget/card_tags', {}, {cache: true})</span><br><span class="line"> 32| !=partial('includes/widget/card_archives', {}, {cache: true})</span><br><span class="line"></span><br><span class="line"> > 33| !=partial('includes/widget/card_webinfo', {}, {cache: true})</span><br><span class="line"> > 34| !=partial('includes/widget/card_bottom_self', {}, {cache: true})</span><br><span class="line"></span><br><span class="line">D:\blog\node_modules\hexo-theme-butterfly\layout\includes\widget\card_webinfo.pug:19</span><br><span class="line"> 17| .webinfo-item</span><br><span class="line"> 18| .item-name=_p('aside.card_webinfo.site_wordcount') + " :"</span><br><span class="line"> > 19| .item-count=totalcount(site)</span><br><span class="line"> > 20| if theme.busuanzi.site_uv</span><br><span class="line"> > 21| .webinfo-item</span><br><span class="line"> > 22| .item-name= _p('aside.card_webinfo.site_uv_name') + " :"</span><br><span class="line"></span><br><span class="line">totalcount is not a function</span><br><span class="line"> at eval (eval at wrap (D:\blog\node_modules\pug-runtime\wrap.js:6:10), <anonymous>:58:57) </span><br><span class="line"> at template (eval at wrap (D:\blog\node_modules\pug-runtime\wrap.js:6:10), <anonymous>:101:7)</span><br><span class="line"> at _View._compiledSync (D:\blog\node_modules\hexo\lib\theme\view.js:132:24)</span><br><span class="line"> at _View.renderSync (D:\blog\node_modules\hexo\lib\theme\view.js:59:25)</span><br><span class="line"> at D:\blog\node_modules\hexo\lib\plugins\helper\partial.js:31:52</span><br><span class="line"> at Cache.apply (D:\blog\node_modules\hexo-util\lib\cache.js:27:46)</span><br><span class="line"> at Object.fragmentCache (D:\blog\node_modules\hexo\lib\plugins\helper\fragment_cache.js:11:34)</span><br><span class="line"> at Object.partial (D:\blog\node_modules\hexo\lib\plugins\helper\partial.js:31:17)</span><br><span class="line"> at eval (eval at wrap (D:\blog\node_modules\pug-runtime\wrap.js:6:10), <anonymous>:1896:46) </span><br><span class="line"> at template (eval at wrap (D:\blog\node_modules\pug-runtime\wrap.js:6:10), <anonymous>:5857:7)</span><br><span class="line"> at _View._compiled (D:\blog\node_modules\hexo\lib\theme\view.js:136:50)</span><br><span class="line"> at _View.render (D:\blog\node_modules\hexo\lib\theme\view.js:39:17)</span><br><span class="line"> at D:\blog\node_modules\hexo\lib\hexo\index.js:64:21</span><br><span class="line"> at tryCatcher (D:\blog\node_modules\bluebird\js\release\util.js:16:23)</span><br><span class="line"> at D:\blog\node_modules\bluebird\js\release\method.js:15:34</span><br><span class="line"> at RouteStream._read (D:\blog\node_modules\hexo\lib\hexo\router.js:47:5)</span><br><span class="line"> at Readable.read (node:internal/streams/readable:496:12)</span><br><span class="line"> at resume_ (node:internal/streams/readable:999:12)</span><br><span class="line"> at process.processTicksAndRejections (node:internal/process/task_queues:82:21)</span><br><span class="line"></span><br></pre></td></tr></table></figure></div>
<h1 id="思路一"><a href="#思路一" class="headerlink" title="思路一"></a>思路一</h1><p>因为很久没更新 ,我第一时间想到的是不是因为node.js 和npm版本太老了?于是就更新了node.js 和npm。</p>
<p>node.js更新我是去官网下载最新版安装包 。</p>
<p>而npm更新则是用命令行更新。</p>
<p>NPM更新到最新版命令:</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">npm install -g npm</span><br></pre></td></tr></table></figure></div>
<h1 id="思路二"><a href="#思路二" class="headerlink" title="思路二"></a>思路二</h1><p>现在电脑上的node.js 和npm均是最新版了,但是hexo s后仍然报错,还是同样的ERROR,但是看到别人却成功了。于是分析了一下报错信息,</p>
<p>发现了这几行东西:</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">ERROR Plugin load failed: hexo-butterfly-clock</span><br><span class="line">Error: ENOENT: no such file or directory, open 'D:\blog\node_modules\hexo-butterfly-clock' </span><br><span class="line">ERROR Plugin load failed: hexo-wordcount</span><br><span class="line">Error: ENOENT: no such file or directory, open 'D:\blog\node_modules\hexo-wordcount'</span><br></pre></td></tr></table></figure></div>
<p>就发现<strong>根本原因是hexo-butterfly-clock和hexo-wordcount这2个插件缺失</strong></p>
<p>于是就立马下载插件</p>
<h2 id="安装hexo-butterfly-clock"><a href="#安装hexo-butterfly-clock" class="headerlink" title="安装hexo-butterfly-clock"></a>安装hexo-butterfly-clock</h2><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">npm install hexo-butterfly-clock --save </span><br></pre></td></tr></table></figure></div>
<p>或者</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">cnpm install hexo-butterfly-clock --save</span><br></pre></td></tr></table></figure></div>
<h2 id="安装hexo-wordcount"><a href="#安装hexo-wordcount" class="headerlink" title="安装hexo-wordcount"></a>安装hexo-wordcount</h2><div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">npm install hexo-wordcount --save</span><br></pre></td></tr></table></figure></div>
<p>或者</p>
<div class="highlight-container" data-rel="Plaintext"><figure class="iseeu highlight plaintext"><table><tr><td class="code"><pre><span class="line">cnpm install hexo-wordcount --save</span><br></pre></td></tr></table></figure></div>
<p>到此,再次hexo s ,可发现问题已解决。</p>
]]></content>
<tags>
<tag>博客</tag>
<tag>博客问题</tag>
</tags>
</entry>
</search>