{"id":493,"date":"2026-08-07T18:51:03","date_gmt":"2026-08-07T10:51:03","guid":{"rendered":"http:\/\/www.millscience.cn\/?p=493"},"modified":"2026-08-07T18:51:05","modified_gmt":"2026-08-07T10:51:05","slug":"cpplearning1","status":"publish","type":"post","link":"https:\/\/www.millscience.cn\/index.php\/cpplearning1\/","title":{"rendered":"c++\u5b66\u4e60day1"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">day1<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C++ \u662f\u4e00\u79cd\u9ad8\u7ea7\u8bed\u8a00\uff0c\u5b83\u662f\u7531 Bjarne Stroustrup \u4e8e 1979 \u5e74\u5728\u8d1d\u5c14\u5b9e\u9a8c\u5ba4\u5f00\u59cb\u8bbe\u8ba1\u5f00\u53d1\u7684\u3002C++ \u8fdb\u4e00\u6b65\u6269\u5145\u548c\u5b8c\u5584\u4e86 C \u8bed\u8a00\uff0c\u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u3002C++ \u53ef\u8fd0\u884c\u4e8e\u591a\u79cd\u5e73\u53f0\u4e0a\uff0c\u5982 Windows\u3001MAC \u64cd\u4f5c\u7cfb\u7edf\u4ee5\u53ca UNIX \u7684\u5404\u79cd\u7248\u672c\u3002<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u7b80\u5355\u7684helloworld\u793a\u4f8b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>#include &lt;iostream>\nusing namespace std;\nint main()\n{\n    cout &lt;&lt; \"Hello, world!\" &lt;&lt; endl;\n    return 0;\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">#include<\/span><span style=\"color: #569CD6\"> <\/span><span style=\"color: #CE9178\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">using<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">namespace<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">std<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">main<\/span><span style=\"color: #D4D4D4\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    cout &lt;&lt; <\/span><span style=\"color: #CE9178\">&quot;Hello, world!&quot;<\/span><span style=\"color: #D4D4D4\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48 C++ \u603b\u8981\u5199 <code>using namespace std;<\/code> \u6216 <code>std::<\/code>\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 C \u8bed\u8a00\u65f6\u4ee3\uff0c\u5982\u679c\u9879\u76ee\u53d8\u5927\uff0c\u4e0d\u540c\u5f00\u53d1\u8005\u5199\u4e86\u540c\u540d\u51fd\u6570\uff08\u6bd4\u5982\u4f60\u5199\u4e86\u4e00\u4e2a <code>printf<\/code>\uff0c\u7b2c\u4e09\u65b9\u5e93\u4e5f\u5199\u4e86\u4e00\u4e2a <code>printf<\/code>\uff09\uff0c\u7f16\u8bd1\u5668\u5c31\u4f1a\u62a5\u9519\u51b2\u7a81\uff0c\u8fd9\u53eb<strong>\u547d\u540d\u7a7a\u95f4\u6c61\u67d3<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">C++ \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5f15\u5165\u4e86 <strong><code>namespace<\/code>\uff08\u547d\u540d\u7a7a\u95f4\uff09<\/strong>\u3002\u4f60\u53ef\u4ee5\u628a\u5b83\u60f3\u8c61\u6210<strong>\u6587\u4ef6\u5939<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f88\u591a\u6587\u4ef6\u653e\u5728\u6839\u76ee\u5f55\u4e0b\u5bb9\u6613\u540c\u540d\u91cd\u53e0\u3002<\/li>\n\n\n\n<li>\u5efa\u7acb\u4e86\u6587\u4ef6\u5939\uff08\u547d\u540d\u7a7a\u95f4\uff09\u4e4b\u540e\uff0cA \u6587\u4ef6\u5939\u91cc\u7684 <code>cout<\/code> \u548c B \u6587\u4ef6\u5939\u91cc\u7684 <code>cout<\/code> \u5c31\u4e92\u4e0d\u5e72\u6270\u4e86\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><code>std<\/code><\/strong> \u5c31\u662f C++ <strong>\u6807\u51c6\u5e93\uff08Standard Library\uff09<\/strong> \u4e13\u5c5e\u7684\u6587\u4ef6\u5939\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8bbf\u95ee\u65b9\u5f0f\u7684\u533a\u522b\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u65b9\u5f0f\u4e00\uff1a\u6309\u9700\u6307\u660e\u201c\u6587\u4ef6\u5939\u201d\uff08\u63a8\u8350\uff09<\/strong> <code>std::cout &lt;&lt; \"Hello World\"; \/\/ \u660e\u786e\u544a\u8bc9\u7f16\u8bd1\u5668\uff1a\u6211\u8981\u7528 std \u6587\u4ef6\u5939\u91cc\u7684 cout<\/code><\/li>\n\n\n\n<li><strong>\u65b9\u5f0f\u4e8c\uff1a\u76f4\u63a5\u6253\u5f00\u201c\u6587\u4ef6\u5939\u201d\uff08\u65b0\u624b\u5e38\u7528\uff09<\/strong> <code>using namespace std; \/\/ \u58f0\u660e\u628a std \u6587\u4ef6\u5939\u76f4\u63a5\u6253\u5f00\uff0c\u540e\u9762\u7684\u4ee3\u7801\u4e0d\u7528\u5199 std:: \u4e86 cout &lt;&lt; \"Hello World\";<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">class \uff08\u7c7b\uff09\u7684\u5f15\u5165<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">c++\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u7c7b\u7684\u5f15\u5165\u5c31\u662f\u5176\u4e2d\u7684\u5173\u952e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u5411\u5bf9\u8c61\uff08Object-Oriented Programming\uff09\u7684\u6838\u5fc3\u662f\u201c\u4e3b\u89d2\/\u5b9e\u4f53\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5b9e\u751f\u6d3b\u4e2d\uff0c\u4f60\u770b\u5230\u4e00\u53ea\u732b\uff0c\u4f60\u4e0d\u4f1a\u628a\u201c\u732b\u7684\u6bdb\u8272\u201d\u548c\u201c\u732b\u4f1a\u55b5\u55b5\u53eb\u201d\u62c6\u6210\u4e24\u4e2a\u72ec\u7acb\u7684\u4e1c\u897f\u3002\u5728\u4f60\u8111\u6d77\u91cc\uff0c<strong>\u732b\u5c31\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u5b9e\u4f53\uff08\u5bf9\u8c61\uff09<\/strong>\uff0c\u5b83\u65e2\u6709\u5c5e\u6027\uff08\u6bdb\u8272\u3001\u4f53\u91cd\uff09\uff0c\u53c8\u6709\u884c\u4e3a\uff08\u5403\u3001\u53eb\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9762\u5411\u5bf9\u8c61\u5c31\u662f\u628a\u201c\u6570\u636e\u201d\u548c\u201c\u64cd\u4f5c\u6570\u636e\u7684\u51fd\u6570\u201d\u6346\u7ed1\u5728\u4e00\u8d77\uff0c\u6253\u5305\u6210\u4e00\u4e2a\u6574\u4f53\uff0c\u8fd9\u4e2a\u6574\u4f53\u5c31\u53eb <strong>\u7c7b\uff08Class\uff09<\/strong>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7c7b\uff08Class\uff09<\/strong>\uff1a\u5c31\u662f\u4e00\u5f20<strong>\u8bbe\u8ba1\u56fe<\/strong>\u3002\u6bd4\u5982\u201c\u732b\u7c7b\u201d\u3002<\/li>\n\n\n\n<li><strong>\u5bf9\u8c61\uff08Object\uff09<\/strong>\uff1a\u5c31\u662f\u6839\u636e\u8bbe\u8ba1\u56fe<strong>\u9020\u51fa\u6765\u7684\u5177\u4f53\u5b9e\u4f53<\/strong>\u3002\u6bd4\u5982\u4f60\u5bb6\u517b\u7684\u90a3\u53ea\u53eb\u201c\u54aa\u54aa\u201d\u7684\u732b\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u5728 C++ \u91cc\uff0c\u6570\u636e\u548c\u51fd\u6570\u5199\u5728\u4e00\u8d77\uff0c\u6784\u6210\u4e86\u201c\u732b\u201d\u8fd9\u4e2a\u7c7b\nclass Cat {\npublic:\n    string name; \/\/ \u5c5e\u6027\uff08\u6570\u636e\uff09\n    int age;     \/\/ \u5c5e\u6027\uff08\u6570\u636e\uff09\n\n    void eat() { \/\/ \u884c\u4e3a\uff08\u51fd\u6570\uff09\n        cout &lt;&lt; name &lt;&lt; \" \u6b63\u5728\u5403\u9c7c\uff01\" &lt;&lt; endl;\n    }\n};\n\nint main() {\n    Cat my_cat;           \/\/ \u5b9e\u4f8b\u5316\u4e00\u4e2a\u5177\u4f53\u7684\u201c\u5bf9\u8c61\u201d\n    my_cat.name = \"\u54aa\u54aa\";\n    my_cat.eat();         \/\/ \u8ba9\u201c\u54aa\u54aa\u201d\u81ea\u5df1\u53bb\u6267\u884c\u201c\u5403\u201d\u7684\u52a8\u4f5c\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u5728 C++ \u91cc\uff0c\u6570\u636e\u548c\u51fd\u6570\u5199\u5728\u4e00\u8d77\uff0c\u6784\u6210\u4e86\u201c\u732b\u201d\u8fd9\u4e2a\u7c7b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Cat<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    string name;<\/span><span style=\"color: #6A9955\"> \/\/ \u5c5e\u6027\uff08\u6570\u636e\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> age;<\/span><span style=\"color: #6A9955\">     \/\/ \u5c5e\u6027\uff08\u6570\u636e\uff09<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">void<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">eat<\/span><span style=\"color: #D4D4D4\">() {<\/span><span style=\"color: #6A9955\"> \/\/ \u884c\u4e3a\uff08\u51fd\u6570\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        cout &lt;&lt; name &lt;&lt; <\/span><span style=\"color: #CE9178\">&quot; \u6b63\u5728\u5403\u9c7c\uff01&quot;<\/span><span style=\"color: #D4D4D4\"> &lt;&lt; endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">int<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">main<\/span><span style=\"color: #D4D4D4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    Cat my_cat;<\/span><span style=\"color: #6A9955\">           \/\/ \u5b9e\u4f8b\u5316\u4e00\u4e2a\u5177\u4f53\u7684\u201c\u5bf9\u8c61\u201d<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">my_cat<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">name<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;\u54aa\u54aa&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">my_cat<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">eat<\/span><span style=\"color: #D4D4D4\">();<\/span><span style=\"color: #6A9955\">         \/\/ \u8ba9\u201c\u54aa\u54aa\u201d\u81ea\u5df1\u53bb\u6267\u884c\u201c\u5403\u201d\u7684\u52a8\u4f5c<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e09\u5927\u7279\u6027\uff1a\u5c01\u88c5\uff0c\u7ee7\u627f\uff0c\u591a\u6001\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5728 C++ \u4e2d\uff0c<code>struct<\/code> \u548c <code>class<\/code> \u51e0\u4e4e\u662f\u4e00\u6837\u7684<\/strong>\uff0c\u7c7b\u7684\u601d\u60f3\u6765\u81ea\u4e0ec\u4e2d\u7684\u7ed3\u6784\u4f53\uff0c\u4ed6\u4eec\u90fd\u53ef\u4ee5\u5b58\u653e\u53d8\u91cf\uff0c\u90fd\u53ef\u4ee5\u8fdb\u884c\u8bbf\u95ee\uff0c\u90fd\u662f\u5b9a\u4e49\u4e86\u4e00\u79cd\u65b0\u7684\u7c7b\u578b\uff0c\u53ef\u4ee5\u5728\u5176\u5b83\u5730\u65b9\u5b9a\u4e49\u548c\u8d4b\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 C++ \u8bed\u6cd5\u91cc\uff0c\u53ef\u4ee5\u7528 <code>struct<\/code> \u5173\u952e\u5b57\u6765\u5199\u7c7b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 C++ \u4e2d\uff0c\u4e0b\u9762\u8fd9\u4e24\u6bb5\u4ee3\u7801<strong>\u529f\u80fd\u5b8c\u5168\u7b49\u4ef7<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7528 <code>struct<\/code> \u5199<\/strong>\uff08\u9ed8\u8ba4\u91cc\u9762\u7684\u53d8\u91cf\u548c\u51fd\u6570\u90fd\u662f\u516c\u5f00 <code>public<\/code> \u7684\uff09\uff1a <code>struct Hero { string name; int hp; void attack() { cout &lt;&lt; name &lt;&lt; \" \u53d1\u8d77\u653b\u51fb\uff01\"; } };<\/code><\/li>\n\n\n\n<li><strong>\u7528 <code>class<\/code> \u5199<\/strong>\uff08\u9ed8\u8ba4\u91cc\u9762\u7684\u53d8\u91cf\u548c\u51fd\u6570\u662f\u9690\u85cf <code>private<\/code> \u7684\uff0c\u6240\u4ee5\u9700\u8981\u5199 <code>public:<\/code>\uff09\uff1a <code>class Hero { public: string name; int hp; void attack() { cout &lt;&lt; name &lt;&lt; \" \u53d1\u8d77\u653b\u51fb\uff01\"; } };<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u51b3chm\u624b\u518c\u6e32\u67d3\u5931\u8d25<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.millscience.cn\/wp-content\/uploads\/2026\/08\/\u5c4f\u5e55\u622a\u56fe-2026-08-06-225520.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/www.millscience.cn\/wp-content\/uploads\/2026\/08\/\u5c4f\u5e55\u622a\u56fe-2026-08-06-225520.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u56fe\uff0c\u624b\u518c\u4efb\u4f55\u5730\u65b9\u90fd\u662f\u7a7a\u767d\u9875\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u7535\u8111\u91cc\u627e\u5230\u8fd9\u4e2a <code>.chm<\/code> \u6587\u4ef6\uff0c<strong>\u53f3\u952e\u70b9\u51fb\u5b83<\/strong> $\\rightarrow$ \u9009\u62e9 <strong>\u201c\u5c5e\u6027\u201d<\/strong>\uff08Properties\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5f39\u51fa\u7684\u5c5e\u6027\u7a97\u53e3\u6700\u4e0b\u65b9\uff0c\u627e\u5230 <strong>\u201c\u89e3\u9664\u9501\u5b9a\u201d<\/strong>\uff08Unblock\uff09\u9009\u9879\uff08\u5982\u4e0b\u56fe\uff0c\u6253\u4e0a\u52fe\u6216\u8005\u70b9\u51fb\u201c\u89e3\u9664\u9501\u5b9a\u201d\u6309\u94ae\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>day1 C++ \u662f\u4e00\u79cd\u9ad8\u7ea7\u8bed\u8a00\uff0c\u5b83\u662f\u7531 Bjarne Stroustrup \u4e8e 1979 \u5e74\u5728\u8d1d\u5c14\u5b9e\u9a8c\u5ba4\u5f00\u59cb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":327,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpp"],"_links":{"self":[{"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/posts\/493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/comments?post=493"}],"version-history":[{"count":2,"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/posts\/493\/revisions"}],"predecessor-version":[{"id":496,"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/posts\/493\/revisions\/496"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/media\/327"}],"wp:attachment":[{"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/media?parent=493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/categories?post=493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.millscience.cn\/index.php\/wp-json\/wp\/v2\/tags?post=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}