{"id":40916,"date":"2025-05-30T12:26:37","date_gmt":"2025-05-30T04:26:37","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/40916.html"},"modified":"2025-05-30T12:26:37","modified_gmt":"2025-05-30T04:26:37","slug":"c-%e5%bc%82%e5%b8%b8%e5%a4%84%e7%90%86%e6%9c%ba%e5%88%b6%e4%b8%8e%e8%87%aa%e5%ae%9a%e4%b9%89%e5%bc%82%e5%b8%b8%e4%bd%93%e7%b3%bb","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/40916.html","title":{"rendered":"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"1.C%E8%AF%AD%E8%A8%80%E4%BC%A0%E7%BB%9F%E7%9A%84%E5%A4%84%E7%90%86%E9%94%99%E8%AF%AF%E7%9A%84%E6%96%B9%E5%BC%8F-toc\" style=\"margin-left:80px\">1.C\u8bed\u8a00\u4f20\u7edf\u7684\u5904\u7406\u9519\u8bef\u7684\u65b9\u5f0f &#x1f60a;<\/p>\n<p id=\"1.%20%E7%BB%88%E6%AD%A2%E7%A8%8B%E5%BA%8F-toc\" style=\"margin-left:120px\">1. \u7ec8\u6b62\u7a0b\u5e8f<\/p>\n<p id=\"2.%20%E8%BF%94%E5%9B%9E%E9%94%99%E8%AF%AF%E7%A0%81-toc\" style=\"margin-left:120px\">2. \u8fd4\u56de\u9519\u8bef\u7801<\/p>\n<p id=\"3.%E5%AE%9E%E9%99%85%E4%BD%BF%E7%94%A8%E4%B8%AD%E7%9A%84%E6%83%85%E5%86%B5-toc\" style=\"margin-left:120px\">3.\u5b9e\u9645\u4f7f\u7528\u4e2d\u7684\u60c5\u51b5<\/p>\n<p id=\"2.%20C%2B%2B%E5%BC%82%E5%B8%B8%E6%A6%82%E5%BF%B5%F0%9F%8C%BC-toc\" style=\"margin-left:80px\">2. C&#043;&#043;\u5f02\u5e38\u6982\u5ff5&#x1f33c;<\/p>\n<p id=\"2.1%20C%2B%2B%E5%BC%82%E5%B8%B8%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5-toc\" style=\"margin-left:120px\">2.1 C&#043;&#043;\u5f02\u5e38\u7684\u57fa\u672c\u6982\u5ff5<\/p>\n<p id=\"2.2%E5%BC%82%E5%B8%B8%E7%9A%84%E6%8A%9B%E5%87%BA%E5%92%8C%E5%8C%B9%E9%85%8D%E5%8E%9F%E5%88%99-toc\" style=\"margin-left:120px\">2.2\u5f02\u5e38\u7684\u629b\u51fa\u548c\u5339\u914d\u539f\u5219<\/p>\n<p id=\"2.3%C2%A0%E5%BC%82%E5%B8%B8%E7%9A%84%E9%87%8D%E6%96%B0%E6%8A%9B%E5%87%BA-toc\" style=\"margin-left:120px\">2.3\u00a0\u5f02\u5e38\u7684\u91cd\u65b0\u629b\u51fa<\/p>\n<p id=\"2.4%20%E5%BC%82%E5%B8%B8%E5%AE%89%E5%85%A8-toc\" style=\"margin-left:120px\">2.4 \u5f02\u5e38\u5b89\u5168<\/p>\n<p id=\"2.5%20%E5%BC%82%E5%B8%B8%E8%A7%84%E8%8C%83-toc\" style=\"margin-left:120px\">2.5 \u5f02\u5e38\u89c4\u8303<\/p>\n<p id=\"3.%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%82%E5%B8%B8%E4%BD%93%E7%B3%BB%20%F0%9F%92%95%F0%9F%98%98-toc\" style=\"margin-left:80px\">3. \u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb &#x1f495;&#x1f618;<\/p>\n<p id=\"3.1%C2%A0%C2%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%82%E5%B8%B8%E7%B1%BB-toc\" style=\"margin-left:120px\">3.1\u00a0\u00a0\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b<\/p>\n<p id=\"3.2%C2%A0%C2%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E5%A4%9A%E4%B8%AA%E5%BC%82%E5%B8%B8%E7%B1%BB%E5%9E%8B-toc\" style=\"margin-left:120px\">3.2\u00a0\u00a0\u81ea\u5b9a\u4e49\u591a\u4e2a\u5f02\u5e38\u7c7b\u578b<\/p>\n<p id=\"3.3.%20%E6%8D%95%E8%8E%B7%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%82%E5%B8%B8-toc\" style=\"margin-left:120px\">3.3. \u6355\u83b7\u81ea\u5b9a\u4e49\u5f02\u5e38<\/p>\n<p id=\"3.4%20%E5%BC%82%E5%B8%B8%E5%B1%82%E6%AC%A1%E7%BB%93%E6%9E%84%E8%AE%BE%E8%AE%A1-toc\" style=\"margin-left:120px\">3.4 \u5f02\u5e38\u5c42\u6b21\u7ed3\u6784\u8bbe\u8ba1<\/p>\n<p id=\"4.C%2B%2B%E6%A0%87%E5%87%86%E5%BA%93%E7%9A%84%E5%BC%82%E5%B8%B8%E4%BD%93%E7%B3%BB%20%F0%9F%98%81%F0%9F%98%81-toc\" style=\"margin-left:80px\">4.C&#043;&#043;\u6807\u51c6\u5e93\u7684\u5f02\u5e38\u4f53\u7cfb &#x1f601;&#x1f601;<\/p>\n<p id=\"5.%E5%BC%82%E5%B8%B8%E7%9A%84%E4%BC%98%E7%BC%BA%E7%82%B9%F0%9F%A4%A3%F0%9F%A4%A3-toc\" style=\"margin-left:80px\">5.\u5f02\u5e38\u7684\u4f18\u7f3a\u70b9&#x1f923;&#x1f923;<\/p>\n<hr id=\"hr-toc\" \/>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337b07d72.gif\" \/><\/p>\n<p>\u00a0\u524d\u8a00&#x1f618;&#x1f618;&#x1f618;<\/p>\n<p>\u5728\u7a0b\u5e8f\u5f00\u53d1\u4e2d&#xff0c;\u9519\u8bef\u548c\u5f02\u5e38\u7684\u5904\u7406\u662f\u81f3\u5173\u91cd\u8981\u7684&#xff0c;\u5b83\u76f4\u63a5\u5f71\u54cd\u5230\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u548c\u7a33\u5b9a\u6027\u3002<span style=\"color:#ed7976\">C\u8bed\u8a00\u7684\u9519\u8bef\u5904\u7406\u4e3b\u8981\u4f9d\u8d56\u8fd4\u56de\u503c\u548c\u9519\u8bef\u7801<\/span>&#xff0c;\u867d\u7136\u8fd9\u79cd\u65b9\u5f0f\u7b80\u5355\u76f4\u63a5&#xff0c;\u4f46\u5728\u590d\u6742\u7684\u7a0b\u5e8f\u4e2d&#xff0c;\u9519\u8bef\u5904\u7406\u4ee3\u7801\u5f80\u5f80\u96be\u4ee5\u7ef4\u62a4\u4e14\u5bb9\u6613\u51fa\u9519\u3002\u76f8\u6bd4\u4e4b\u4e0b&#xff0c;C&#043;&#043;\u5f15\u5165\u7684\u5f02\u5e38\u5904\u7406\u673a\u5236\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u4e3a\u9ad8\u6548\u548c\u7075\u6d3b\u7684\u9519\u8bef\u5904\u7406\u65b9\u5f0f&#xff0c;\u4f7f\u5f97\u7a0b\u5e8f\u7684\u9519\u8bef\u7ba1\u7406\u66f4\u52a0\u6e05\u6670\u548c\u4f18\u96c5\u3002<\/p>\n<p>\u672c\u8282\u5c06\u8be6\u7ec6\u4ecb\u7ecdC&#043;&#043;\u5f02\u5e38\u5904\u7406\u7684\u76f8\u5173\u6982\u5ff5\u3001\u7528\u6cd5\u4ee5\u53ca\u5982\u4f55\u901a\u8fc7\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb\u6765\u6ee1\u8db3\u7a0b\u5e8f\u7684\u9700\u6c42\u3002\u540c\u65f6&#xff0c;\u6211\u4eec\u5c06\u5bf9\u6bd4C\u8bed\u8a00\u7684\u4f20\u7edf\u9519\u8bef\u5904\u7406\u65b9\u5f0f&#xff0c;\u5206\u6790C&#043;&#043;\u5f02\u5e38\u673a\u5236\u7684\u4f18\u7f3a\u70b9&#xff0c;\u5e76\u63a2\u8ba8\u6807\u51c6\u5e93\u4e2d\u63d0\u4f9b\u7684\u5f02\u5e38\u4f53\u7cfb&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528C&#043;&#043;\u7684\u5f02\u5e38\u5904\u7406\u529f\u80fd\u3002<\/p>\n<h4 id=\"1.C%E8%AF%AD%E8%A8%80%E4%BC%A0%E7%BB%9F%E7%9A%84%E5%A4%84%E7%90%86%E9%94%99%E8%AF%AF%E7%9A%84%E6%96%B9%E5%BC%8F\">1.C\u8bed\u8a00\u4f20\u7edf\u7684\u5904\u7406\u9519\u8bef\u7684\u65b9\u5f0f &#x1f60a;<\/h4>\n<p>C\u8bed\u8a00\u4f20\u7edf\u7684\u9519\u8bef\u5904\u7406\u673a\u5236\u4e3b\u8981\u6709\u4e24\u79cd\u65b9\u5f0f&#xff1a;<span style=\"color:#ed7976\">\u7ec8\u6b62\u7a0b\u5e8f\u548c\u8fd4\u56de\u9519\u8bef\u7801\u3002<\/span>\u8fd9\u4e24\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355\u6613\u7528&#xff0c;\u4f46\u5404\u81ea\u4e5f\u6709\u5176\u5c40\u9650\u6027\u548c\u7f3a\u9677&#xff0c;\u5c24\u5176\u662f\u5728\u5904\u7406\u590d\u6742\u9519\u8bef\u6216\u5927\u89c4\u6a21\u7a0b\u5e8f\u65f6&#xff0c;\u5f80\u5f80\u4f1a\u5bfc\u81f4\u7ef4\u62a4\u4e0a\u7684\u56f0\u96be\u3002\u00a0<\/p>\n<h5 id=\"1.%20%E7%BB%88%E6%AD%A2%E7%A8%8B%E5%BA%8F\">1. \u7ec8\u6b62\u7a0b\u5e8f<\/h5>\n<p>\u4e00\u79cd\u5e38\u89c1\u7684\u9519\u8bef\u5904\u7406\u65b9\u5f0f\u662f\u76f4\u63a5\u7ec8\u6b62\u7a0b\u5e8f&#xff0c;\u8fd9\u79cd\u65b9\u5f0f\u901a\u5e38\u662f\u901a\u8fc7\u4f7f\u7528assert\u5b8f\u5b9e\u73b0\u7684\u3002assert\u4f1a\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u5bf9\u6761\u4ef6\u8fdb\u884c\u68c0\u67e5&#xff0c;\u5982\u679c\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u5219\u7a0b\u5e8f\u4f1a\u7acb\u5373\u7ec8\u6b62\u5e76\u8f93\u51fa\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>#include &lt;assert.h&gt;<\/p>\n<p>void foo(int x) {<br \/>\n    assert(x !&#061; 0);  \/\/ \u5982\u679cx\u4e3a0&#xff0c;\u7a0b\u5e8f\u7ec8\u6b62<br \/>\n    printf(&#034;x is not zero\\\\n&#034;);<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    foo(0);  \/\/ \u89e6\u53d1\u65ad\u8a00&#xff0c;\u7a0b\u5e8f\u7ec8\u6b62<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"521\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337b183f8.png\" width=\"1103\" \/><\/p>\n<p>\u7f3a\u9677&#xff1a;<\/p>\n<ul>\n<li>\u7528\u6237\u96be\u4ee5\u63a5\u53d7&#xff1a;\u7a0b\u5e8f\u76f4\u63a5\u7ec8\u6b62&#xff0c;\u5c24\u5176\u662f\u5f53\u53d1\u751f\u4e00\u4e9b\u5c0f\u9519\u8bef\u6216\u8fb9\u754c\u6761\u4ef6\u65f6&#xff0c;\u7528\u6237\u4f53\u9a8c\u5f88\u5dee\u3002<\/li>\n<li>\u9002\u7528\u573a\u666f\u6709\u9650&#xff1a;\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u4e25\u91cd\u9519\u8bef&#xff08;\u5982\u5185\u5b58\u9519\u8bef\u3001\u96640\u9519\u8bef\u7b49&#xff09;&#xff0c;\u4f46\u4e0d\u9002\u5408\u6240\u6709\u60c5\u51b5&#xff0c;\u56e0\u4e3a\u5927\u591a\u6570\u7a0b\u5e8f\u9519\u8bef\u5e76\u4e0d\u9700\u8981\u5b8c\u5168\u7ec8\u6b62\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<p>\u5f53\u7a0b\u5e8f\u9047\u5230\u65e0\u6cd5\u6062\u590d\u7684\u9519\u8bef\u65f6&#xff0c;assert\u53ef\u4ee5\u6709\u6548\u5730\u5e2e\u52a9\u5f00\u53d1\u8005\u68c0\u6d4b\u51fa\u95ee\u9898\u3002\u4f46\u662f&#xff0c;\u5f53\u7a0b\u5e8f\u51fa\u73b0\u4e00\u4e9b\u975e\u81f4\u547d\u9519\u8bef\u65f6&#xff0c;\u7528\u6237\u5e0c\u671b\u7a0b\u5e8f\u80fd\u591f\u4f18\u96c5\u5730\u5904\u7406&#xff0c;\u800c\u4e0d\u662f\u76f4\u63a5\u5d29\u6e83\u3002\u00a0<\/p>\n<h5 id=\"2.%20%E8%BF%94%E5%9B%9E%E9%94%99%E8%AF%AF%E7%A0%81\">2. \u8fd4\u56de\u9519\u8bef\u7801<\/h5>\n<p>\u53e6\u4e00\u4e2a\u5e38\u89c1\u7684\u9519\u8bef\u5904\u7406\u65b9\u5f0f\u662f\u901a\u8fc7\u8fd4\u56de\u9519\u8bef\u7801\u6765\u901a\u77e5\u7a0b\u5e8f\u51fa\u73b0\u4e86\u95ee\u9898\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728C\u8bed\u8a00\u4e2d\u975e\u5e38\u666e\u904d&#xff0c;\u8bb8\u591a\u6807\u51c6\u5e93\u51fd\u6570&#xff08;\u5982malloc\u3001fopen\u7b49&#xff09;\u90fd\u901a\u8fc7\u8fd4\u56de\u4e00\u4e2a\u7279\u6b8a\u7684\u9519\u8bef\u7801\u6765\u8868\u793a\u51fd\u6570\u6267\u884c\u5931\u8d25\u3002\u5f00\u53d1\u8005\u9700\u8981\u6839\u636e\u8fd4\u56de\u503c\u6765\u5224\u65ad\u9519\u8bef&#xff0c;\u5e76\u505a\u76f8\u5e94\u7684\u5904\u7406\u3002<\/p>\n<p>\u6bd4\u5982&#xff0c;malloc\u5728\u5206\u914d\u5185\u5b58\u5931\u8d25\u65f6\u8fd4\u56deNULL&#xff0c;fopen\u5728\u6253\u5f00\u6587\u4ef6\u5931\u8d25\u65f6\u8fd4\u56deNULL&#xff0c;<span style=\"color:#ed7976\">errno\u5219\u662f\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u6700\u8fd1\u4e00\u6b21\u7cfb\u7edf\u8c03\u7528\u7684\u9519\u8bef\u7801\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"243\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337b57eb5.png\" width=\"641\" \/><\/p>\n<p>\u7f3a\u9677&#xff1a;<\/p>\n<ul>\n<li>\u9700\u8981\u624b\u52a8\u68c0\u67e5\u9519\u8bef\u7801&#xff1a;\u7a0b\u5e8f\u5458\u5fc5\u987b\u68c0\u67e5\u6bcf\u4e2a\u51fd\u6570\u8c03\u7528\u7684\u8fd4\u56de\u503c&#xff0c;\u4ee5\u4fbf\u53d1\u73b0\u9519\u8bef\u3002\u8fd9\u5bfc\u81f4\u4e86\u5927\u91cf\u91cd\u590d\u7684\u9519\u8bef\u5904\u7406\u4ee3\u7801&#xff0c;\u589e\u52a0\u4e86\u7ef4\u62a4\u6210\u672c\u3002<\/li>\n<li>\u9519\u8bef\u4fe1\u606f\u4e0d\u591f\u76f4\u89c2&#xff1a;\u867d\u7136\u53ef\u4ee5\u901a\u8fc7errno\u6765\u83b7\u53d6\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f&#xff0c;\u4f46\u8fd9\u901a\u5e38\u4e0d\u5982\u5f02\u5e38\u673a\u5236\u76f4\u89c2\u3002\u9519\u8bef\u7801\u672c\u8eab\u901a\u5e38\u662f\u6570\u5b57&#xff0c;\u7f3a\u4e4f\u5bf9\u9519\u8bef\u672c\u8d28\u7684\u63cf\u8ff0&#xff0c;\u9700\u8981\u989d\u5916\u7684\u903b\u8f91\u53bb\u7406\u89e3\u9519\u8bef\u7801\u7684\u542b\u4e49\u3002<\/li>\n<li>\u9519\u8bef\u5904\u7406\u5206\u6563&#xff1a;\u7a0b\u5e8f\u4e2d\u591a\u5904\u8c03\u7528\u7684\u51fd\u6570\u53ef\u80fd\u4f1a\u8fd4\u56de\u4e0d\u540c\u7684\u9519\u8bef\u7801&#xff0c;\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\u7684\u903b\u8f91\u5f80\u5f80\u5206\u6563\u5728\u4ee3\u7801\u7684\u5404\u4e2a\u5730\u65b9&#xff0c;\u5bfc\u81f4\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u5dee\u3002<\/li>\n<\/ul>\n<h5 id=\"3.%E5%AE%9E%E9%99%85%E4%BD%BF%E7%94%A8%E4%B8%AD%E7%9A%84%E6%83%85%E5%86%B5\">3.\u5b9e\u9645\u4f7f\u7528\u4e2d\u7684\u60c5\u51b5<\/h5>\n<p>\u5728\u5b9e\u9645\u7684C\u8bed\u8a00\u5f00\u53d1\u4e2d&#xff0c;\u8fd4\u56de\u9519\u8bef\u7801\u662f\u6700\u5e38\u89c1\u7684\u9519\u8bef\u5904\u7406\u65b9\u5f0f\u3002C\u8bed\u8a00\u6ca1\u6709\u5185\u5efa\u7684\u5f02\u5e38\u673a\u5236&#xff0c;\u6240\u4ee5\u7a0b\u5e8f\u5458\u5fc5\u987b\u901a\u8fc7\u68c0\u67e5\u6bcf\u4e2a\u51fd\u6570\u8c03\u7528\u7684\u8fd4\u56de\u503c\u6765\u624b\u52a8\u5904\u7406\u9519\u8bef\u3002\u5bf9\u4e8e\u4e00\u4e9b\u7b80\u5355\u7684\u9519\u8bef&#xff0c;\u8fd4\u56de\u9519\u8bef\u7801\u901a\u5e38\u8db3\u591f\u3002\u4f46\u5bf9\u4e8e\u8f83\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u9519\u8bef\u7801\u7684\u4f7f\u7528\u53ef\u80fd\u53d8\u5f97\u5197\u957f\u4e14\u96be\u4ee5\u7ef4\u62a4\u3002<\/p>\n<p>\u5728\u4e00\u4e9b\u975e\u5e38\u4e25\u91cd\u7684\u9519\u8bef\u60c5\u51b5\u4e0b&#xff08;\u5982\u5185\u5b58\u5206\u914d\u5931\u8d25\u3001\u6587\u4ef6\u64cd\u4f5c\u5931\u8d25\u7b49&#xff09;&#xff0c;\u5f00\u53d1\u8005\u6709\u65f6\u4f1a\u9009\u62e9\u76f4\u63a5\u7ec8\u6b62\u7a0b\u5e8f\u3002\u4f8b\u5982&#xff0c;\u5728\u53d1\u73b0\u5185\u5b58\u5206\u914d\u5931\u8d25\u65f6&#xff0c;\u7a0b\u5e8f\u53ef\u80fd\u65e0\u6cd5\u7ee7\u7eed\u6267\u884c&#xff0c;\u8fd9\u65f6\u76f4\u63a5\u901a\u8fc7exit()\u6216\u5176\u4ed6\u65b9\u5f0f\u7ec8\u6b62\u7a0b\u5e8f\u53ef\u4ee5\u907f\u514d\u8fdb\u4e00\u6b65\u7684\u9519\u8bef\u3002<\/p>\n<h4 id=\"2.%20C%2B%2B%E5%BC%82%E5%B8%B8%E6%A6%82%E5%BF%B5%F0%9F%8C%BC\">2. C&#043;&#043;\u5f02\u5e38\u6982\u5ff5&#x1f33c;<\/h4>\n<p>C&#043;&#043;\u7684\u5f02\u5e38\u673a\u5236\u662f\u4e00\u79cd\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u9519\u8bef\u548c\u7279\u6b8a\u60c5\u51b5\u7684\u673a\u5236&#xff0c;\u53ef\u4ee5\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4e2d\u65ad\u5f53\u524d\u7684\u63a7\u5236\u6d41&#xff0c;\u5e76\u8df3\u8f6c\u5230\u4e00\u4e2a\u53ef\u4ee5\u5904\u7406\u8be5\u9519\u8bef\u7684\u4ee3\u7801\u5757\u3002\u8fd9\u79cd\u673a\u5236\u4f7f\u5f97\u7a0b\u5e8f\u80fd\u591f\u4f18\u96c5\u5730\u5e94\u5bf9\u5404\u79cd\u9519\u8bef&#xff0c;\u800c\u4e0d\u662f\u50cfC\u8bed\u8a00\u90a3\u6837\u4f9d\u8d56\u8fd4\u56de\u9519\u8bef\u7801\u6216\u76f4\u63a5\u7ec8\u6b62\u7a0b\u5e8f\u3002\u00a0<\/p>\n<h5 id=\"2.1%20C%2B%2B%E5%BC%82%E5%B8%B8%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\">2.1 C&#043;&#043;\u5f02\u5e38\u7684\u57fa\u672c\u6982\u5ff5<\/h5>\n<li>\n<p>\u5f02\u5e38 (Exception)<\/p>\n<ul>\n<li>\u5f02\u5e38\u662f\u6307\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u9047\u5230\u7684\u4e00\u79cd<span style=\"color:#ed7976\">\u9519\u8bef\u6216\u610f\u5916\u60c5\u51b5<\/span>&#xff0c;\u8fd9\u79cd\u60c5\u51b5\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u65e0\u6cd5\u6b63\u5e38\u7ee7\u7eed\u6267\u884c\u3002<\/li>\n<li>\u5f02\u5e38\u901a\u8fc7<span style=\"color:#ed7976\">throw\u5173\u952e\u5b57<\/span>\u629b\u51fa&#xff0c;\u8868\u793a\u9519\u8bef\u5df2\u7ecf\u53d1\u751f\u3002<\/li>\n<li>\u5f02\u5e38\u53ef\u4ee5\u662f\u4efb\u610f\u7684C&#043;&#043;\u5bf9\u8c61&#xff08;\u5982\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u3001\u81ea\u5b9a\u4e49\u7c7b\u5bf9\u8c61&#xff09;&#xff0c;\u4f46\u901a\u5e38\u5efa\u8bae\u4f7f\u7528\u6807\u51c6\u5e93\u4e2d\u7684\u5f02\u5e38\u7c7b&#xff08;\u5982std::exception\u53ca\u5176\u6d3e\u751f\u7c7b&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5f02\u5e38\u5904\u7406\u673a\u5236 C&#043;&#043;\u901a\u8fc7\u4e09\u79cd\u5173\u952e\u5b57\u5b9e\u73b0\u5f02\u5e38\u5904\u7406&#xff1a;<\/p>\n<ul>\n<li><span style=\"color:#ed7976\">try&#xff1a;\u5b9a\u4e49\u4e00\u4e2a\u4ee3\u7801\u5757&#xff0c;\u7528\u4e8e\u5305\u542b\u53ef\u80fd\u53d1\u751f\u5f02\u5e38\u7684\u4ee3\u7801\u3002<\/span><\/li>\n<li><span style=\"color:#be191c\">throw&#xff1a;\u5728\u5f02\u5e38\u53d1\u751f\u65f6&#xff0c;\u7528\u4e8e\u629b\u51fa\u5f02\u5e38\u3002<\/span><\/li>\n<li><span style=\"color:#ed7976\">catch&#xff1a;\u6355\u83b7\u5f02\u5e38&#xff0c;\u5e76\u5b9a\u4e49\u5982\u4f55\u5904\u7406\u5b83\u3002<\/span><\/li>\n<\/ul>\n<\/li>\n<h5 id=\"2.2%E5%BC%82%E5%B8%B8%E7%9A%84%E6%8A%9B%E5%87%BA%E5%92%8C%E5%8C%B9%E9%85%8D%E5%8E%9F%E5%88%99\">2.2\u5f02\u5e38\u7684\u629b\u51fa\u548c\u5339\u914d\u539f\u5219<\/h5>\n<p>1. \u5f02\u5e38\u662f\u901a\u8fc7\u629b\u51fa\u5bf9\u8c61\u800c\u5f15\u53d1\u7684&#xff0c;\u8be5\u5bf9\u8c61\u7684\u7c7b\u578b\u51b3\u5b9a\u4e86\u5e94\u8be5\u6fc0\u6d3b\u54ea\u4e2acatch\u7684\u5904\u7406\u4ee3\u7801\u3002<\/p>\n<p>2. \u88ab\u9009\u4e2d\u7684\u5904\u7406\u4ee3\u7801\u662f\u8c03\u7528\u94fe\u4e2d\u4e0e\u8be5\u5bf9\u8c61\u7c7b\u578b\u5339\u914d\u4e14\u79bb\u629b\u51fa\u5f02\u5e38\u4f4d\u7f6e\u6700\u8fd1\u7684\u90a3\u4e00\u4e2a\u3002<\/p>\n<p>3. \u629b\u51fa\u5f02\u5e38\u5bf9\u8c61\u540e&#xff0c;\u4f1a\u751f\u6210\u4e00\u4e2a\u5f02\u5e38\u5bf9\u8c61\u7684\u62f7\u8d1d&#xff0c;\u56e0\u4e3a\u629b\u51fa\u7684\u5f02\u5e38\u5bf9\u8c61\u53ef\u80fd\u662f\u4e00\u4e2a\u4e34\u65f6\u5bf9\u8c61&#xff0c;<\/p>\n<p>\u6240\u4ee5\u4f1a\u751f\u6210\u4e00\u4e2a\u62f7\u8d1d\u5bf9\u8c61&#xff0c;\u8fd9\u4e2a\u62f7\u8d1d\u7684\u4e34\u65f6\u5bf9\u8c61\u4f1a\u5728\u88abcatch\u4ee5\u540e\u9500\u6bc1\u3002&#xff08;\u8fd9\u91cc\u7684\u5904\u7406\u7c7b\u4f3c<\/p>\n<p>\u4e8e\u51fd\u6570\u7684\u4f20\u503c\u8fd4\u56de&#xff09;<\/p>\n<p>4. catch(&#8230;)\u53ef\u4ee5\u6355\u83b7\u4efb\u610f\u7c7b\u578b\u7684\u5f02\u5e38&#xff0c;\u95ee\u9898\u662f\u4e0d\u77e5\u9053\u5f02\u5e38\u9519\u8bef\u662f\u4ec0\u4e48\u3002<\/p>\n<p>5. \u5b9e\u9645\u4e2d\u629b\u51fa\u548c\u6355\u83b7\u7684\u5339\u914d\u539f\u5219\u6709\u4e2a\u4f8b\u5916&#xff0c;\u5e76\u4e0d\u90fd\u662f\u7c7b\u578b\u5b8c\u5168\u5339\u914d&#xff0c;\u53ef\u4ee5\u629b\u51fa\u7684\u6d3e\u751f\u7c7b\u5bf9\u8c61&#xff0c;<\/p>\n<p>\u4f7f\u7528\u57fa\u7c7b\u6355\u83b7&#xff0c;\u8fd9\u4e2a\u5728\u5b9e\u9645\u4e2d\u975e\u5e38\u5b9e\u7528&#xff0c;\u6211\u4eec\u540e\u9762\u4f1a\u8be6\u7ec6\u8bb2\u89e3\u8fd9\u4e2a\u3002<\/p>\n<p>\u5728\u51fd\u6570\u8c03\u7528\u94fe\u4e2d\u5f02\u5e38\u6808\u5c55\u5f00\u5339\u914d\u539f\u5219<\/p>\n<p>1. \u9996\u5148\u68c0\u67e5throw\u672c\u8eab\u662f\u5426\u5728try\u5757\u5185\u90e8&#xff0c;\u5982\u679c\u662f\u518d\u67e5\u627e\u5339\u914d\u7684catch\u8bed\u53e5\u3002\u5982\u679c\u6709\u5339\u914d\u7684&#xff0c;\u5219<\/p>\n<p>\u8c03\u5230catch\u7684\u5730\u65b9\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>2. \u6ca1\u6709\u5339\u914d\u7684catch\u5219\u9000\u51fa\u5f53\u524d\u51fd\u6570\u6808&#xff0c;\u7ee7\u7eed\u5728\u8c03\u7528\u51fd\u6570\u7684\u6808\u4e2d\u8fdb\u884c\u67e5\u627e\u5339\u914d\u7684catch\u3002<\/p>\n<p>3. \u5982\u679c\u5230\u8fbemain\u51fd\u6570\u7684\u6808&#xff0c;\u4f9d\u65e7\u6ca1\u6709\u5339\u914d\u7684&#xff0c;\u5219\u7ec8\u6b62\u7a0b\u5e8f\u3002\u4e0a\u8ff0\u8fd9\u4e2a\u6cbf\u7740\u8c03\u7528\u94fe\u67e5\u627e\u5339\u914d\u7684<\/p>\n<p>catch\u5b50\u53e5\u7684\u8fc7\u7a0b\u79f0\u4e3a\u6808\u5c55\u5f00\u3002\u6240\u4ee5\u5b9e\u9645\u4e2d\u6211\u4eec\u6700\u540e\u90fd\u8981\u52a0\u4e00\u4e2acatch(&#8230;)\u6355\u83b7\u4efb\u610f\u7c7b\u578b\u7684\u5f02<\/p>\n<p>\u5e38&#xff0c;\u5426\u5219\u5f53\u6709\u5f02\u5e38\u6ca1\u6355\u83b7&#xff0c;\u7a0b\u5e8f\u5c31\u4f1a\u76f4\u63a5\u7ec8\u6b62\u3002<\/p>\n<p>4. \u627e\u5230\u5339\u914d\u7684catch\u5b50\u53e5\u5e76\u5904\u7406\u4ee5\u540e&#xff0c;\u4f1a\u7ee7\u7eed\u6cbf\u7740catch\u5b50\u53e5\u540e\u9762<span style=\"color:#be191c\">\u7ee7\u7eed\u6267\u884c\u3002<\/span><\/p>\n<p>\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"340\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337b7bd13.png\" width=\"369\" \/><\/p>\n<p>\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"680\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337b919d7.png\" width=\"1032\" \/><\/p>\n<p>\u4ee3\u7801\u6848\u4f8b&#xff1a;<\/p>\n<p>double Division(int a, int b)<br \/>\n{<br \/>\n\/\/ \u5f53b &#061;&#061; 0\u65f6\u629b\u51fa\u5f02\u5e38<br \/>\nif (b &#061;&#061; 0)<br \/>\nthrow &#034;Division by zero condition!&#034;;<br \/>\nelse<br \/>\nreturn ((double)a \/ (double)b);<br \/>\n}<br \/>\nvoid Func()<br \/>\n{<br \/>\nint len, time;<br \/>\ncin &gt;&gt; len &gt;&gt; time;<br \/>\ncout &lt;&lt; Division(len, time) &lt;&lt; endl;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\ntry {<br \/>\nFunc();<br \/>\n}<br \/>\ncatch (const char* errmsg&#xff09; {<br \/>\ncout &lt;&lt; errmsg &lt;&lt; endl;<br \/>\n}<br \/>\ncatch(&#8230;){<br \/>\ncout&lt;&lt;&#034;unkown exception&#034;&lt;&lt;endl;<br \/>\n}<br \/>\nreturn 0;<br \/>\n} <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u5728 C&#043;&#043; \u4e2d\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u673a\u5236\u6765\u7ba1\u7406\u9519\u8bef&#xff08;\u7279\u522b\u662f\u9664\u4ee5\u96f6\u7684\u9519\u8bef&#xff09;\u3002\u901a\u8fc7\u4f7f\u7528 <span style=\"color:#ed7976\">throw \u548c catch<\/span>&#xff0c;\u7a0b\u5e8f\u53ef\u4ee5\u4f18\u96c5\u5730\u5904\u7406\u5f02\u5e38&#xff0c;\u907f\u514d\u5d29\u6e83\u5e76\u63d0\u4f9b\u53cb\u597d\u7684\u9519\u8bef\u4fe1\u606f\u3002\u867d\u7136\u5f53\u524d\u7684\u5f02\u5e38\u5904\u7406\u7b80\u5355\u76f4\u89c2&#xff0c;\u4f46\u53ef\u4ee5\u8fdb\u4e00\u6b65\u6539\u8fdb&#xff0c;\u91c7\u7528\u6807\u51c6\u5f02\u5e38\u7c7b\u548c\u66f4\u591a\u8f93\u5165\u9a8c\u8bc1&#xff0c;\u4ee5\u589e\u5f3a\u4ee3\u7801\u7684\u5065\u58ee\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<h5 id=\"2.3%C2%A0%E5%BC%82%E5%B8%B8%E7%9A%84%E9%87%8D%E6%96%B0%E6%8A%9B%E5%87%BA\">2.3\u00a0\u5f02\u5e38\u7684\u91cd\u65b0\u629b\u51fa<\/h5>\n<p>C&#043;&#043; \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e2d\u7684 \u5f02\u5e38\u91cd\u65b0\u629b\u51fa&#xff08;rethrow&#xff09;\u3002\u5f53\u6355\u83b7\u5230\u5f02\u5e38\u65f6&#xff0c;\u5982\u679c\u5f53\u524d\u51fd\u6570\u65e0\u6cd5\u5904\u7406\u5f02\u5e38&#xff0c;\u6216\u5e0c\u671b\u66f4\u4e0a\u5c42\u7684\u51fd\u6570\u5904\u7406\u5f02\u5e38&#xff0c;\u53ef\u4ee5\u4f7f\u7528 throw; \u8bed\u53e5\u91cd\u65b0\u629b\u51fa\u5f02\u5e38\u3002\u8fd9\u79cd\u673a\u5236\u5141\u8bb8\u5728\u5f53\u524d catch \u5757\u4e2d\u5904\u7406\u4e00\u4e9b\u5fc5\u8981\u7684\u64cd\u4f5c&#xff08;\u5982\u8d44\u6e90\u91ca\u653e&#xff09;&#xff0c;\u7136\u540e\u5c06\u5f02\u5e38\u4f20\u9012\u7ed9\u8c03\u7528\u94fe\u4e2d\u7684\u66f4\u5916\u5c42\u51fd\u6570\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\u3002\u00a0<\/p>\n<p>\u4ee3\u7801\u5206\u6790<\/p>\n<p>1. Division \u51fd\u6570<\/p>\n<p>\u8be5\u51fd\u6570\u5b9e\u73b0\u4e86\u4e24\u4e2a\u6574\u6570\u7684\u9664\u6cd5\u64cd\u4f5c&#xff1a;<\/p>\n<ul>\n<li>\u8f93\u5165&#xff1a;\u4e24\u4e2a\u6574\u6570 a \u548c b\u3002<\/li>\n<li>\u529f\u80fd&#xff1a;\u5982\u679c b &#061;&#061; 0&#xff0c;\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38&#xff0c;\u63d0\u793a &#034;\u9664\u4ee5\u96f6\u9519\u8bef&#034;\u3002\u5426\u5219&#xff0c;\u6267\u884c\u9664\u6cd5\u5e76\u8fd4\u56de\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>double Division(int a, int b) {<br \/>\n    if (b &#061;&#061; 0)  \/\/ \u68c0\u67e5\u9664\u6570\u662f\u5426\u4e3a\u96f6<br \/>\n        throw &#034;Division by zero condition!&#034;;  \/\/ \u629b\u51fa\u5f02\u5e38<br \/>\n    return (double)a \/ (double)b;  \/\/ \u8fd4\u56de\u9664\u6cd5\u7ed3\u679c<br \/>\n}<\/p>\n<p>\u00a02. Func \u51fd\u6570<\/p>\n<p>\u8be5\u51fd\u6570\u6267\u884c\u9664\u6cd5\u64cd\u4f5c\u5e76\u6f14\u793a\u5f02\u5e38\u7684\u91cd\u65b0\u629b\u51fa\u3002\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4&#xff1a;<\/p>\n<ul>\n<li>\u8f93\u5165&#xff1a;\u4ece\u7528\u6237\u8bfb\u53d6\u4e24\u4e2a\u6574\u6570 len \u548c time\u3002<\/li>\n<li>\u529f\u80fd&#xff1a;\u8c03\u7528 Division \u51fd\u6570\u8fdb\u884c\u9664\u6cd5\u8ba1\u7b97\u3002\u5982\u679c\u53d1\u751f\u9664\u4ee5\u96f6\u9519\u8bef&#xff0c;\u5219\u6355\u83b7\u5f02\u5e38\u5e76\u6267\u884c\u4e00\u4e9b\u6e05\u7406\u64cd\u4f5c&#xff08;\u5982\u91ca\u653e\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58&#xff09;\u3002<\/li>\n<\/ul>\n<p>catch (&#8230;) \u6355\u83b7\u6240\u6709\u7c7b\u578b\u7684\u5f02\u5e38\u3002<\/p>\n<p>delete[] array; \u91ca\u653e\u5728 Func \u51fd\u6570\u4e2d\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58\u3002<\/p>\n<p>\u7136\u540e&#xff0c;throw; \u91cd\u65b0\u629b\u51fa\u5f02\u5e38&#xff0c;\u5c06\u5176\u4f20\u9012\u5230 main \u51fd\u6570\u4e2d\u7684 catch \u5757\u5904\u7406\u3002<\/p>\n<p>void Func() {<br \/>\n    int* array &#061; new int[10];  \/\/ \u52a8\u6001\u5206\u914d\u5185\u5b58<br \/>\n    try {<br \/>\n        int len, time;<br \/>\n        cin &gt;&gt; len &gt;&gt; time;  \/\/ \u4ece\u7528\u6237\u8f93\u5165\u83b7\u53d6\u4e24\u4e2a\u6574\u6570<br \/>\n        cout &lt;&lt; Division(len, time) &lt;&lt; endl;  \/\/ \u8c03\u7528Division\u8fdb\u884c\u9664\u6cd5\u64cd\u4f5c<br \/>\n    } catch (&#8230;) {<br \/>\n        \/\/ \u6355\u83b7\u6240\u6709\u5f02\u5e38<br \/>\n        cout &lt;&lt; &#034;delete []&#034; &lt;&lt; array &lt;&lt; endl;<br \/>\n        delete[] array;  \/\/ \u91ca\u653e\u5185\u5b58<br \/>\n        throw;  \/\/ \u91cd\u65b0\u629b\u51fa\u5f02\u5e38<br \/>\n    }<br \/>\n    \/\/ \u5728\u5f02\u5e38\u672a\u53d1\u751f\u65f6\u91ca\u653e\u5185\u5b58<br \/>\n    cout &lt;&lt; &#034;delete []&#034; &lt;&lt; array &lt;&lt; endl;<br \/>\n    delete[] array;<br \/>\n}<\/p>\n<p>\u00a03. main \u51fd\u6570<\/p>\n<p>main \u51fd\u6570\u5305\u542b\u4e86\u4e00\u4e2a try-catch \u5757&#xff0c;\u8d1f\u8d23\u6355\u83b7\u4ece Func \u51fd\u6570\u4f20\u9012\u4e0a\u6765\u7684\u5f02\u5e38&#xff1a;<\/p>\n<ul>\n<li>\u6355\u83b7 const char* \u7c7b\u578b\u7684\u5f02\u5e38&#xff08;\u5373 Division by zero condition! \u5f02\u5e38&#xff09;\u3002<\/li>\n<li>\u6253\u5370\u5f02\u5e38\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p>int main() {<br \/>\n    try {<br \/>\n        Func();  \/\/ \u8c03\u7528Func\u6267\u884c\u64cd\u4f5c<br \/>\n    } catch (const char* errmsg) {  \/\/ \u6355\u83b7\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u5f02\u5e38<br \/>\n        cout &lt;&lt; errmsg &lt;&lt; endl;  \/\/ \u6253\u5370\u5f02\u5e38\u4fe1\u606f<br \/>\n    }<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u00a0\u5de5\u4f5c\u6d41\u7a0b\u4e0e\u903b\u8f91<\/p>\n<li>\u6267\u884c main \u51fd\u6570&#xff0c;\u8c03\u7528 Func()\u3002<\/li>\n<li>\u5728 Func \u4e2d&#xff1a;\n<ul>\n<li>\u4ece\u7528\u6237\u8f93\u5165 len \u548c time&#xff0c;\u8c03\u7528 Division(len, time) \u6267\u884c\u9664\u6cd5\u3002<\/li>\n<li>\u5982\u679c time &#061;&#061; 0&#xff0c;Division \u4f1a\u629b\u51fa &#034;Division by zero condition!&#034; \u5f02\u5e38\u3002<\/li>\n<li>catch (&#8230;) \u6355\u83b7\u8be5\u5f02\u5e38&#xff0c;\u5e76\u6267\u884c\u5f02\u5e38\u5904\u7406&#xff1a;\n<ul>\n<li>\u6253\u5370\u6b63\u5728\u91ca\u653e\u7684\u52a8\u6001\u6570\u7ec4 array\u3002<\/li>\n<li>\u91ca\u653e\u5185\u5b58&#xff08;delete[] array&#xff09;\u3002<\/li>\n<li>\u4f7f\u7528 throw; \u91cd\u65b0\u629b\u51fa\u5f02\u5e38&#xff0c;\u5c06\u5176\u4ea4\u7ed9 main \u51fd\u6570\u7684 catch \u5757\u5904\u7406\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u5728 main \u4e2d&#xff1a;\n<ul>\n<li>\u6355\u83b7\u5230\u5f02\u5e38 &#034;Division by zero condition!&#034;&#xff0c;\u5e76\u6253\u5370\u8be5\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u5f02\u5e38\u7684\u91cd\u65b0\u629b\u51fa<\/p>\n<p>throw; \u7684\u4f5c\u7528<\/p>\n<ul>\n<li>\u91cd\u65b0\u629b\u51fa\u6355\u83b7\u7684\u5f02\u5e38&#xff1a;throw; \u53ef\u4ee5\u5c06\u5f53\u524d\u6355\u83b7\u7684\u5f02\u5e38\u91cd\u65b0\u629b\u51fa&#xff0c;\u5e76\u5c06\u5176\u4f20\u9012\u7ed9\u8c03\u7528\u94fe\u4e2d\u7684\u66f4\u5916\u5c42 catch \u5757\u8fdb\u884c\u5904\u7406\u3002\u8fd9\u4f7f\u5f97\u5f02\u5e38\u53ef\u4ee5\u88ab\u4e0a\u5c42\u51fd\u6570\u8fdb\u4e00\u6b65\u5904\u7406\u3002<\/li>\n<li>\u5f02\u5e38\u4f20\u9012&#xff1a;\u5728 catch \u4e2d\u8fdb\u884c\u4e00\u4e9b\u5fc5\u8981\u7684\u5904\u7406&#xff08;\u5982\u8d44\u6e90\u91ca\u653e\u3001\u65e5\u5fd7\u8bb0\u5f55\u7b49&#xff09;\u540e&#xff0c;\u53ef\u4ee5\u9009\u62e9\u5c06\u5f02\u5e38\u4ea4\u7ed9\u5916\u5c42\u7684 catch \u5757\u8fdb\u884c\u540e\u7eed\u5904\u7406\u3002<\/li>\n<\/ul>\n<p>\u91cd\u65b0\u629b\u51fa\u573a\u666f<\/p>\n<li>\u8d44\u6e90\u6e05\u7406&#xff1a;\u5728 catch \u4e2d\u6267\u884c\u8d44\u6e90\u91ca\u653e\u3001\u65e5\u5fd7\u8bb0\u5f55\u7b49\u64cd\u4f5c\u540e&#xff0c;\u518d\u5c06\u5f02\u5e38\u4f20\u9012\u7ed9\u66f4\u5916\u5c42\u7684\u51fd\u6570\u5904\u7406\u3002<\/li>\n<li>\u4e2d\u65ad\u5f02\u5e38\u4f20\u64ad&#xff1a;\u6709\u65f6\u5019&#xff0c;catch \u53ea\u9700\u8981\u5904\u7406\u4e00\u4e9b\u4e34\u65f6\u7684\u9519\u8bef\u6216\u7b80\u5355\u7684\u8d44\u6e90\u6e05\u7406\u5de5\u4f5c&#xff0c;\u800c\u4e0d\u5173\u5fc3\u5f02\u5e38\u7684\u6700\u7ec8\u5904\u7406&#xff0c;\u4f7f\u7528 throw; \u53ef\u4ee5\u8ba9\u66f4\u5916\u5c42\u7684 catch \u5757\u8fdb\u884c\u5b9e\u9645\u7684\u9519\u8bef\u5904\u7406\u3002<\/li>\n<li>\u5206\u5c42\u5904\u7406&#xff1a;\u590d\u6742\u7684\u9519\u8bef\u5904\u7406\u53ef\u4ee5\u5206\u5c42\u6267\u884c\u3002\u5185\u5c42\u51fd\u6570\u5148\u8fdb\u884c\u4e00\u4e9b\u6e05\u7406\u5de5\u4f5c&#xff0c;\u800c\u5177\u4f53\u7684\u9519\u8bef\u5904\u7406\u548c\u6062\u590d\u64cd\u4f5c\u4ea4\u7ed9\u5916\u5c42\u51fd\u6570\u3002<\/li>\n<p>\u603b\u7ed3<\/p>\n<li>\u5f02\u5e38\u91cd\u65b0\u629b\u51fa&#xff08;throw;&#xff09;\u662f C&#043;&#043; \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e2d\u7684\u4e00\u79cd\u975e\u5e38\u6709\u7528\u7684\u529f\u80fd\u3002\u5b83\u5141\u8bb8\u6355\u83b7\u7684\u5f02\u5e38\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u7ee7\u7eed\u4f20\u9012\u5230\u4e0a\u5c42\u51fd\u6570&#xff0c;\u8ba9\u66f4\u4e0a\u5c42\u7684\u4ee3\u7801\u5904\u7406\u5b9e\u9645\u7684\u9519\u8bef\u3002<\/li>\n<li>\u5728\u672c\u4f8b\u4e2d&#xff0c;catch \u5757\u5904\u7406\u4e86\u4e00\u4e9b\u4e34\u65f6\u7684\u8d44\u6e90\u6e05\u7406\u5de5\u4f5c&#xff0c;\u7136\u540e\u4f7f\u7528 throw; \u5c06\u5f02\u5e38\u91cd\u65b0\u629b\u51fa&#xff0c;\u6700\u7ec8\u7531 main \u51fd\u6570\u4e2d\u7684 catch \u5757\u6355\u83b7\u5e76\u8f93\u51fa\u5f02\u5e38\u4fe1\u606f\u3002<\/li>\n<li>\u5f02\u5e38\u5904\u7406\u4e2d\u7684\u8d44\u6e90\u7ba1\u7406&#xff08;\u4f8b\u5982\u5185\u5b58\u91ca\u653e&#xff09;\u975e\u5e38\u91cd\u8981&#xff0c;\u56e0\u4e3a\u5b83\u786e\u4fdd\u5373\u4f7f\u53d1\u751f\u5f02\u5e38&#xff0c;\u52a8\u6001\u5206\u914d\u7684\u8d44\u6e90\u4e5f\u80fd\u591f\u6b63\u786e\u91ca\u653e&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u7b49\u95ee\u9898\u3002<\/li>\n<p>\u8fd9\u79cd\u673a\u5236\u53ef\u4ee5\u4f7f\u5f02\u5e38\u5904\u7406\u66f4\u5177\u7075\u6d3b\u6027&#xff0c;\u9002\u5e94\u4e0d\u540c\u5c42\u7ea7\u7684\u9519\u8bef\u5904\u7406\u9700\u6c42&#xff0c;\u540c\u65f6\u4fdd\u8bc1\u8d44\u6e90\u7684\u6709\u6548\u91ca\u653e\u3002<\/p>\n<h5 id=\"2.4%20%E5%BC%82%E5%B8%B8%E5%AE%89%E5%85%A8\">2.4 \u5f02\u5e38\u5b89\u5168<\/h5>\n<p>\u5728 C&#043;&#043; \u4e2d&#xff0c;\u5f02\u5e38\u5b89\u5168\u6307\u7684\u662f\u5728\u51fa\u73b0\u5f02\u5e38\u65f6&#xff0c;\u786e\u4fdd\u7a0b\u5e8f\u8d44\u6e90\u7ba1\u7406\u6b63\u786e\u3001\u6570\u636e\u4e00\u81f4\u6027\u4e0d\u88ab\u7834\u574f\u3002\u6784\u9020\u51fd\u6570\u548c\u6790\u6784\u51fd\u6570\u662f\u5f02\u5e38\u5b89\u5168\u7684\u5173\u952e\u70b9&#xff1a;<\/p>\n<li>\n<p>\u6784\u9020\u51fd\u6570&#xff1a;\u907f\u514d\u5728\u6784\u9020\u51fd\u6570\u4e2d\u629b\u51fa\u5f02\u5e38&#xff0c;\u5426\u5219\u5bf9\u8c61\u53ef\u80fd\u4e0d\u5b8c\u5168\u521d\u59cb\u5316\u3002\u4f7f\u7528\u4e34\u65f6\u5bf9\u8c61\u6216\u51fd\u6570\u6765\u907f\u514d\u590d\u6742\u64cd\u4f5c\u4e2d\u51fa\u73b0\u5f02\u5e38\u3002<\/p>\n<\/li>\n<li>\n<p>\u6790\u6784\u51fd\u6570&#xff1a;\u5c3d\u91cf\u4e0d\u8981\u5728\u6790\u6784\u51fd\u6570\u4e2d\u629b\u51fa\u5f02\u5e38&#xff0c;\u56e0\u4e3a\u8fd9\u53ef\u80fd\u5bfc\u81f4\u8d44\u6e90\u6cc4\u6f0f\u6216\u7a0b\u5e8f\u5d29\u6e83\u3002\u5982\u679c\u5fc5\u987b\u5904\u7406\u5f02\u5e38&#xff0c;\u6355\u83b7\u5e76\u907f\u514d\u4f20\u64ad\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d44\u6e90\u7ba1\u7406\u4e2d\u7684\u5f02\u5e38&#xff1a;\u5728\u52a8\u6001\u5185\u5b58\u5206\u914d&#xff08;new&#xff09;\u548c\u9501\u7ba1\u7406\u4e2d&#xff0c;\u5f02\u5e38\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u6216\u6b7b\u9501\u3002RAII&#xff08;\u8d44\u6e90\u83b7\u53d6\u5373\u521d\u59cb\u5316&#xff09;\u6a21\u5f0f\u80fd\u81ea\u52a8\u7ba1\u7406\u8d44\u6e90&#xff0c;\u786e\u4fdd\u5f02\u5e38\u53d1\u751f\u65f6\u6b63\u786e\u91ca\u653e\u8d44\u6e90\u3002<\/p>\n<\/li>\n<li>\n<p>\u667a\u80fd\u6307\u9488&#xff1a;\u4f7f\u7528\u667a\u80fd\u6307\u9488&#xff08;\u5982 std::unique_ptr&#xff09;\u53ef\u4ee5\u81ea\u52a8\u7ba1\u7406\u5185\u5b58&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<\/li>\n<p>RAII \u548c\u667a\u80fd\u6307\u9488\u662f\u89e3\u51b3\u5f02\u5e38\u5b89\u5168\u95ee\u9898\u7684\u91cd\u8981\u5de5\u5177&#xff0c;\u5b83\u4eec\u901a\u8fc7\u5728\u5bf9\u8c61\u751f\u547d\u5468\u671f\u5185\u81ea\u52a8\u7ba1\u7406\u8d44\u6e90\u6765\u786e\u4fdd\u4ee3\u7801\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n<h5 id=\"2.5%20%E5%BC%82%E5%B8%B8%E8%A7%84%E8%8C%83\">2.5 \u5f02\u5e38\u89c4\u8303<\/h5>\n<p>1. \u5f02\u5e38\u89c4\u683c\u8bf4\u660e\u7684\u76ee\u7684\u662f\u4e3a\u4e86\u8ba9\u51fd\u6570\u4f7f\u7528\u8005\u77e5\u9053\u8be5\u51fd\u6570\u53ef\u80fd\u629b\u51fa\u7684\u5f02\u5e38\u6709\u54ea\u4e9b\u3002 \u53ef\u4ee5\u5728\u51fd\u6570\u7684<\/p>\n<p>\u540e\u9762\u63a5throw(\u7c7b\u578b)&#xff0c;\u5217\u51fa\u8fd9\u4e2a\u51fd\u6570\u53ef\u80fd\u629b\u63b7\u7684\u6240\u6709\u5f02\u5e38\u7c7b\u578b\u3002<\/p>\n<p>2. \u51fd\u6570\u7684\u540e\u9762\u63a5throw()&#xff0c;\u8868\u793a\u51fd\u6570\u4e0d\u629b\u5f02\u5e38\u3002<\/p>\n<p>3. \u82e5\u65e0\u5f02\u5e38\u63a5\u53e3\u58f0\u660e&#xff0c;\u5219\u6b64\u51fd\u6570\u53ef\u4ee5\u629b\u63b7\u4efb\u4f55\u7c7b\u578b\u7684\u5f02\u5e38\u3002\u00a0<\/p>\n<p>\/\/ \u8fd9\u91cc\u8868\u793a\u8fd9\u4e2a\u51fd\u6570\u4f1a\u629b\u51faA\/B\/C\/D\u4e2d\u7684\u67d0\u79cd\u7c7b\u578b\u7684\u5f02\u5e38<br \/>\nvoid fun() throw(A&#xff0c;B&#xff0c;C&#xff0c;D);<br \/>\n\/\/ \u8fd9\u91cc\u8868\u793a\u8fd9\u4e2a\u51fd\u6570\u53ea\u4f1a\u629b\u51fabad_alloc\u7684\u5f02\u5e38<br \/>\nvoid* operator new (std::size_t size) throw (std::bad_alloc);<br \/>\n\/\/ \u8fd9\u91cc\u8868\u793a\u8fd9\u4e2a\u51fd\u6570\u4e0d\u4f1a\u629b\u51fa\u5f02\u5e38<br \/>\nvoid* operator delete (std::size_t size, void* ptr) throw();<br \/>\n\/\/ C&#043;&#043;11 \u4e2d\u65b0\u589e\u7684noexcept&#xff0c;\u8868\u793a\u4e0d\u4f1a\u629b\u5f02\u5e38<br \/>\nthread() noexcept;<br \/>\nthread (thread&amp;&amp; x) noexcept; <\/p>\n<h4 id=\"3.%20%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%82%E5%B8%B8%E4%BD%93%E7%B3%BB%20%F0%9F%92%95%F0%9F%98%98\">3. \u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb &#x1f495;&#x1f618;<\/h4>\n<p>\u5728 C&#043;&#043; \u4e2d&#xff0c;\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb\u6307\u7684\u662f\u5b9a\u4e49\u81ea\u5df1\u7684\u5f02\u5e38\u7c7b&#xff0c;\u7528\u4e8e\u8868\u793a\u7279\u5b9a\u7c7b\u578b\u7684\u9519\u8bef\u6216\u5f02\u5e38\u60c5\u51b5\u3002\u8fd9\u6837\u53ef\u4ee5\u4f7f\u5f02\u5e38\u5904\u7406\u66f4\u5177\u53ef\u8bfb\u6027\u548c\u7075\u6d3b\u6027&#xff0c;\u65b9\u4fbf\u533a\u5206\u4e0d\u540c\u7c7b\u578b\u7684\u9519\u8bef\u3002<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"411\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337be802a.png\" width=\"1043\" \/><\/p>\n<h5 id=\"3.1%C2%A0%C2%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%82%E5%B8%B8%E7%B1%BB\">3.1\u00a0\u00a0\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b<\/h5>\n<p>\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b\u901a\u5e38\u7ee7\u627f\u81ea\u6807\u51c6\u5e93\u4e2d\u7684 std::exception \u7c7b&#xff0c;\u6216\u8005\u66f4\u5e38\u89c1\u7684\u662f\u76f4\u63a5\u7ee7\u627f\u81ea std::runtime_error \u6216 std::logic_error\u3002<\/p>\n<p>\u57fa\u672c\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u7ee7\u627f std::exception \u6216\u5176\u5b50\u7c7b&#xff1a;\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b\u5e94\u7ee7\u627f\u81ea std::exception \u6216 std::runtime_error&#xff0c;\u5e76\u91cd\u5199\u6784\u9020\u51fd\u6570\u6765\u4f20\u9012\u9519\u8bef\u6d88\u606f\u3002<\/li>\n<li>\u6dfb\u52a0\u6784\u9020\u51fd\u6570\u548c\u6210\u5458\u51fd\u6570&#xff1a;\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u6784\u9020\u51fd\u6570&#xff0c;\u7528\u6765\u521d\u59cb\u5316\u5f02\u5e38\u4fe1\u606f\u3002<\/li>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;stdexcept&gt;<br \/>\n#include &lt;string&gt;<\/p>\n<p>\/\/ \u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b&#xff0c;\u7ee7\u627f\u81ea std::runtime_error<br \/>\nclass MyException : public std::runtime_error {<br \/>\npublic:<br \/>\n    MyException(const std::string&amp; message)<br \/>\n        : std::runtime_error(message) {}  \/\/ \u8c03\u7528\u57fa\u7c7b\u6784\u9020\u51fd\u6570<br \/>\n};<\/p>\n<p>void testFunction() {<br \/>\n    throw MyException(&#034;Something went wrong!&#034;);<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    try {<br \/>\n        testFunction();<br \/>\n    } catch (const MyException&amp; e) {<br \/>\n        std::cout &lt;&lt; &#034;Caught MyException: &#034; &lt;&lt; e.what() &lt;&lt; std::endl;<br \/>\n    } catch (const std::exception&amp; e) {<br \/>\n        std::cout &lt;&lt; &#034;Caught std::exception: &#034; &lt;&lt; e.what() &lt;&lt; std::endl;<br \/>\n    }<br \/>\n    return 0;<br \/>\n}<\/p>\n<h5 id=\"3.2%C2%A0%C2%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E5%A4%9A%E4%B8%AA%E5%BC%82%E5%B8%B8%E7%B1%BB%E5%9E%8B\">3.2\u00a0\u00a0\u81ea\u5b9a\u4e49\u591a\u4e2a\u5f02\u5e38\u7c7b\u578b<\/h5>\n<p>\u53ef\u4ee5\u521b\u5efa\u4e0d\u540c\u7684\u5f02\u5e38\u7c7b\u578b\u6765\u8868\u793a\u4e0d\u540c\u7684\u9519\u8bef\u60c5\u5883\u3002\u6bcf\u79cd\u5f02\u5e38\u7c7b\u578b\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u9519\u8bef\u4fe1\u606f&#xff0c;\u6216\u4e0d\u540c\u7684\u903b\u8f91\u5904\u7406<\/p>\n<p>class FileNotFoundException : public std::runtime_error {<br \/>\npublic:<br \/>\n    FileNotFoundException(const std::string&amp; filename)<br \/>\n        : std::runtime_error(&#034;File not found: &#034; &#043; filename), filename(filename) {}<\/p>\n<p>    const std::string&amp; getFilename() const { return filename; }<\/p>\n<p>private:<br \/>\n    std::string filename;<br \/>\n};<\/p>\n<p>class InvalidInputException : public std::invalid_argument {<br \/>\npublic:<br \/>\n    InvalidInputException(const std::string&amp; message)<br \/>\n        : std::invalid_argument(message) {}<br \/>\n};<\/p>\n<p>\/\/ \u4f7f\u7528\u793a\u4f8b<br \/>\ntry {<br \/>\n    throw FileNotFoundException(&#034;data.txt&#034;);<br \/>\n} catch (const FileNotFoundException&amp; e) {<br \/>\n    std::cout &lt;&lt; e.what() &lt;&lt; &#034; Filename: &#034; &lt;&lt; e.getFilename() &lt;&lt; std::endl;<br \/>\n}<\/p>\n<h5 id=\"3.3.%20%E6%8D%95%E8%8E%B7%E8%87%AA%E5%AE%9A%E4%B9%89%E5%BC%82%E5%B8%B8\">3.3. \u6355\u83b7\u81ea\u5b9a\u4e49\u5f02\u5e38<\/h5>\n<p>\u5728 try-catch \u5757\u4e2d\u6355\u83b7\u81ea\u5b9a\u4e49\u5f02\u5e38\u65f6&#xff0c;\u5e94\u8be5\u4f7f\u7528\u9002\u5f53\u7684\u5f02\u5e38\u7c7b\u578b\u6355\u83b7&#xff0c;\u786e\u4fdd\u6b63\u786e\u5904\u7406\u7279\u5b9a\u7684\u9519\u8bef\u3002<\/p>\n<p>try {<br \/>\n    throw InvalidInputException(&#034;Invalid input provided&#034;);<br \/>\n} catch (const InvalidInputException&amp; e) {<br \/>\n    std::cout &lt;&lt; &#034;Caught InvalidInputException: &#034; &lt;&lt; e.what() &lt;&lt; std::endl;<br \/>\n} catch (const std::exception&amp; e) {<br \/>\n    std::cout &lt;&lt; &#034;Caught a generic exception: &#034; &lt;&lt; e.what() &lt;&lt; std::endl;<br \/>\n}<\/p>\n<h5 id=\"3.4%20%E5%BC%82%E5%B8%B8%E5%B1%82%E6%AC%A1%E7%BB%93%E6%9E%84%E8%AE%BE%E8%AE%A1\">3.4 \u5f02\u5e38\u5c42\u6b21\u7ed3\u6784\u8bbe\u8ba1<\/h5>\n<ul>\n<li>\u57fa\u7c7b&#xff1a;std::exception \u6216 std::runtime_error \u7528\u4f5c\u57fa\u7c7b&#xff0c;\u5b9a\u4e49\u901a\u7528\u7684\u63a5\u53e3&#xff08;\u5982 what()&#xff09;\u3002<\/li>\n<li>\u5b50\u7c7b&#xff1a;\u53ef\u4ee5\u4e3a\u6bcf\u79cd\u5177\u4f53\u9519\u8bef\u7c7b\u578b\u521b\u5efa\u5b50\u7c7b&#xff0c;\u7ee7\u627f\u57fa\u7c7b\u5e76\u6269\u5c55\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u65b9\u5f0f\u4f7f\u5f97\u5f02\u5e38\u4f53\u7cfb\u66f4\u52a0\u6e05\u6670\u3001\u53ef\u6269\u5c55\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb\u7684\u6838\u5fc3\u662f\u901a\u8fc7\u7ee7\u627f\u73b0\u6709\u7684\u5f02\u5e38\u7c7b&#xff08;\u5982 std::exception \u6216 std::runtime_error&#xff09;\u6765\u521b\u5efa\u7b26\u5408\u7279\u5b9a\u9700\u6c42\u7684\u5f02\u5e38\u7c7b\u578b\u3002\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u5f02\u5e38\u533a\u5206&#xff0c;\u5e2e\u52a9\u7f16\u5199\u66f4\u5177\u8868\u73b0\u529b\u548c\u53ef\u7ef4\u62a4\u6027\u7684\u4ee3\u7801\u3002<\/p>\n<h4 id=\"4.C%2B%2B%E6%A0%87%E5%87%86%E5%BA%93%E7%9A%84%E5%BC%82%E5%B8%B8%E4%BD%93%E7%B3%BB%20%F0%9F%98%81%F0%9F%98%81\">4.C&#043;&#043;\u6807\u51c6\u5e93\u7684\u5f02\u5e38\u4f53\u7cfb &#x1f601;&#x1f601;<\/h4>\n<p>C&#043;&#043; \u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u6807\u51c6\u7684\u5f02\u5e38&#xff0c;\u5b9a\u4e49\u5728 \u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u6807\u51c6\u7684\u5f02\u5e38\u3002\u5b83\u4eec\u662f\u4ee5\u7236\u5b50\u7c7b\u5c42\u6b21\u7ed3\u6784\u7ec4\u7ec7\u8d77\u6765\u7684&#xff0c;\u5982\u4e0b\u6240\u793a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"547\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042636-6839337c2ed4e.png\" width=\"606\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"562\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042636-6839337c6d7fc.png\" width=\"610\" \/><\/p>\n<p>\u8bf4\u660e&#xff1a;\u5b9e\u9645\u4e2d\u6211\u4eec\u53ef\u4ee5\u53ef\u4ee5\u53bb\u7ee7\u627fexception\u7c7b\u5b9e\u73b0\u81ea\u5df1\u7684\u5f02\u5e38\u7c7b\u3002\u4f46\u662f\u5b9e\u9645\u4e2d\u5f88\u591a\u516c\u53f8\u50cf\u4e0a\u9762\u4e00\u6837\u81ea\u5df1\u5b9a\u4e49\u4e00\u5957\u5f02\u5e38\u7ee7\u627f\u4f53\u7cfb\u3002\u56e0\u4e3aC&#043;&#043;\u6807\u51c6\u5e93\u8bbe\u8ba1\u7684\u4e0d\u591f\u597d\u7528 \u00a0<\/p>\n<p>int main()<br \/>\n{<br \/>\ntry{<br \/>\nvector&lt;int&gt; v(10, 5);<br \/>\n\/\/ \u8fd9\u91cc\u5982\u679c\u7cfb\u7edf\u5185\u5b58\u4e0d\u591f\u4e5f\u4f1a\u629b\u5f02\u5e38<br \/>\nv.reserve(1000000000);<br \/>\n\/\/ \u8fd9\u91cc\u8d8a\u754c\u4f1a\u629b\u5f02\u5e38<br \/>\nv.at(10) &#061; 100;<br \/>\n}<br \/>\ncatch (const exception&amp; e) \/\/ \u8fd9\u91cc\u6355\u83b7\u7236\u7c7b\u5bf9\u8c61\u5c31\u53ef\u4ee5<br \/>\n{<br \/>\ncout &lt;&lt; e.what() &lt;&lt; endl;<br \/>\n}<br \/>\ncatch (&#8230;)<br \/>\n{<br \/>\ncout &lt;&lt; &#034;Unkown Exception&#034; &lt;&lt; endl;<br \/>\n}<br \/>\nreturn 0;<br \/>\n} <\/p>\n<h4 id=\"5.%E5%BC%82%E5%B8%B8%E7%9A%84%E4%BC%98%E7%BC%BA%E7%82%B9%F0%9F%A4%A3%F0%9F%A4%A3\">5.\u5f02\u5e38\u7684\u4f18\u7f3a\u70b9&#x1f923;&#x1f923;<\/h4>\n<p>C&#043;&#043;\u5f02\u5e38\u7684\u4f18\u70b9&#xff1a;<\/p>\n<p>1. \u5f02\u5e38\u5bf9\u8c61\u5b9a\u4e49\u597d\u4e86&#xff0c;\u76f8\u6bd4\u9519\u8bef\u7801\u7684\u65b9\u5f0f\u53ef\u4ee5\u6e05\u6670\u51c6\u786e\u7684\u5c55\u793a\u51fa\u9519\u8bef\u7684\u5404\u79cd\u4fe1\u606f&#xff0c;\u751a\u81f3\u53ef\u4ee5\u5305<\/p>\n<p>\u542b\u5806\u6808\u8c03\u7528\u7684\u4fe1\u606f&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u5e2e\u52a9\u66f4\u597d\u7684\u5b9a\u4f4d\u7a0b\u5e8f\u7684bug\u3002<\/p>\n<p>2. \u8fd4\u56de\u9519\u8bef\u7801\u7684\u4f20\u7edf\u65b9\u5f0f\u6709\u4e2a\u5f88\u5927\u7684\u95ee\u9898\u5c31\u662f&#xff0c;\u5728\u51fd\u6570\u8c03\u7528\u94fe\u4e2d&#xff0c;\u6df1\u5c42\u7684\u51fd\u6570\u8fd4\u56de\u4e86\u9519\u8bef&#xff0c;\u90a3<\/p>\n<p>\u4e48\u6211\u4eec\u5f97\u5c42\u5c42\u8fd4\u56de\u9519\u8bef&#xff0c;\u6700\u5916\u5c42\u624d\u80fd\u62ff\u5230\u9519\u8bef&#xff0c;\u5177\u4f53\u770b\u4e0b\u9762\u7684\u8be6\u7ec6\u89e3\u91ca\u3002<\/p>\n<p>\/\/ 1.\u4e0b\u9762\u8fd9\u6bb5\u4f2a\u4ee3\u7801\u6211\u4eec\u53ef\u4ee5\u770b\u5230ConnnectSql\u4e2d\u51fa\u9519\u4e86&#xff0c;\u5148\u8fd4\u56de\u7ed9ServerStart&#xff0c;<br \/>\nServerStart\u518d\u8fd4\u56de\u7ed9main\u51fd\u6570&#xff0c;main\u51fd\u6570\u518d\u9488\u5bf9\u95ee\u9898\u5904\u7406\u5177\u4f53\u7684\u9519\u8bef\u3002<br \/>\n\/\/ 2.\u5982\u679c\u662f\u5f02\u5e38\u4f53\u7cfb&#xff0c;\u4e0d\u7ba1\u662fConnnectSql\u8fd8\u662fServerStart\u53ca\u8c03\u7528\u51fd\u6570\u51fa\u9519&#xff0c;\u90fd\u4e0d\u7528\u68c0\u67e5&#xff0c;\u56e0<br \/>\n\u4e3a\u629b\u51fa\u7684\u5f02\u5e38\u5f02\u5e38\u4f1a\u76f4\u63a5\u8df3\u5230main\u51fd\u6570\u4e2dcatch\u6355\u83b7\u7684\u5730\u65b9&#xff0c;main\u51fd\u6570\u76f4\u63a5\u5904\u7406\u9519\u8bef\u3002<br \/>\nint ConnnectSql()<br \/>\n{<br \/>\n\/\/ \u7528\u6237\u540d\u5bc6\u7801\u9519\u8bef<br \/>\nif (&#8230;)<br \/>\nreturn 1;<br \/>\n\/\/ \u6743\u9650\u4e0d\u8db3<br \/>\nif (&#8230;)<br \/>\nreturn 2;<br \/>\n}<br \/>\nint ServerStart() {<br \/>\nif (int ret &#061; ConnnectSql() &lt; 0)<br \/>\nreturn ret;<br \/>\nint fd &#061; socket()<br \/>\nif&#xff08;fd &lt; 0&#xff09;<br \/>\nreturn errno;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\nif(ServerStart()&lt;0)<br \/>\n&#8230;<br \/>\nreturn 0;<br \/>\n} <\/p>\n<p>3. \u5f88\u591a\u7684\u7b2c\u4e09\u65b9\u5e93\u90fd\u5305\u542b\u5f02\u5e38&#xff0c;\u6bd4\u5982boost\u3001gtest\u3001gmock\u7b49\u7b49\u5e38\u7528\u7684\u5e93&#xff0c;\u90a3\u4e48\u6211\u4eec\u4f7f\u7528\u5b83\u4eec<\/p>\n<p>\u4e5f\u9700\u8981\u4f7f\u7528\u5f02\u5e38\u3002<\/p>\n<p>4. \u90e8\u5206\u51fd\u6570\u4f7f\u7528\u5f02\u5e38\u66f4\u597d\u5904\u7406&#xff0c;\u6bd4\u5982\u6784\u9020\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u503c&#xff0c;\u4e0d\u65b9\u4fbf\u4f7f\u7528\u9519\u8bef\u7801\u65b9\u5f0f\u5904\u7406\u3002\u6bd4\u5982<\/p>\n<p>T&amp; operator\u8fd9\u6837\u7684\u51fd\u6570&#xff0c;\u5982\u679cpos\u8d8a\u754c\u4e86\u53ea\u80fd\u4f7f\u7528\u5f02\u5e38\u6216\u8005\u7ec8\u6b62\u7a0b\u5e8f\u5904\u7406&#xff0c;\u6ca1\u529e\u6cd5\u901a\u8fc7\u8fd4\u56de<\/p>\n<p>\u503c\u8868\u793a\u9519\u8bef\u3002<\/p>\n<p>C&#043;&#043;\u5f02\u5e38\u7684\u7f3a\u70b9&#xff1a;<\/p>\n<p>1. \u5f02\u5e38\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u4e71\u8df3&#xff0c;\u5e76\u4e14\u975e\u5e38\u7684\u6df7\u4e71&#xff0c;\u5e76\u4e14\u662f\u8fd0\u884c\u65f6\u51fa\u9519\u629b\u5f02\u5e38\u5c31\u4f1a\u4e71\u8df3\u3002\u8fd9\u4f1a<\/p>\n<p>\u5bfc\u81f4\u6211\u4eec\u8ddf\u8e2a\u8c03\u8bd5\u65f6\u4ee5\u53ca\u5206\u6790\u7a0b\u5e8f\u65f6&#xff0c;\u6bd4\u8f83\u56f0\u96be\u3002<\/p>\n<p>2. \u5f02\u5e38\u4f1a\u6709\u4e00\u4e9b\u6027\u80fd\u7684\u5f00\u9500\u3002\u5f53\u7136\u5728\u73b0\u4ee3\u786c\u4ef6\u901f\u5ea6\u5f88\u5feb\u7684\u60c5\u51b5\u4e0b&#xff0c;\u8fd9\u4e2a\u5f71\u54cd\u57fa\u672c\u5ffd\u7565\u4e0d\u8ba1\u3002<\/p>\n<p>3. C&#043;&#043;\u6ca1\u6709\u5783\u573e\u56de\u6536\u673a\u5236&#xff0c;\u8d44\u6e90\u9700\u8981\u81ea\u5df1\u7ba1\u7406\u3002\u6709\u4e86\u5f02\u5e38\u975e\u5e38\u5bb9\u6613\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u3001\u6b7b\u9501\u7b49\u5f02\u5e38<\/p>\n<p>\u5b89\u5168\u95ee\u9898\u3002\u8fd9\u4e2a\u9700\u8981\u4f7f\u7528RAII\u6765\u5904\u7406\u8d44\u6e90\u7684\u7ba1\u7406\u95ee\u9898\u3002\u5b66\u4e60\u6210\u672c\u8f83\u9ad8\u3002<\/p>\n<p>4. C&#043;&#043;\u6807\u51c6\u5e93\u7684\u5f02\u5e38\u4f53\u7cfb\u5b9a\u4e49\u5f97\u4e0d\u597d&#xff0c;\u5bfc\u81f4\u5927\u5bb6\u5404\u81ea\u5b9a\u4e49\u5404\u81ea\u7684\u5f02\u5e38\u4f53\u7cfb&#xff0c;\u975e\u5e38\u7684\u6df7\u4e71\u3002<\/p>\n<p>5. \u5f02\u5e38\u5c3d\u91cf\u89c4\u8303\u4f7f\u7528&#xff0c;\u5426\u5219\u540e\u679c\u4e0d\u582a\u8bbe\u60f3&#xff0c;\u968f\u610f\u629b\u5f02\u5e38&#xff0c;\u5916\u5c42\u6355\u83b7\u7684\u7528\u6237\u82e6\u4e0d\u582a\u8a00\u3002\u6240\u4ee5\u5f02\u5e38<\/p>\n<p>\u89c4\u8303\u6709\u4e24\u70b9&#xff1a;\u4e00\u3001\u629b\u51fa\u5f02\u5e38\u7c7b\u578b\u90fd\u7ee7\u627f\u81ea\u4e00\u4e2a\u57fa\u7c7b\u3002\u4e8c\u3001\u51fd\u6570\u662f\u5426\u629b\u5f02\u5e38\u3001\u629b\u4ec0\u4e48\u5f02\u5e38&#xff0c;\u90fd<\/p>\n<p>\u4f7f\u7528 func&#xff08;&#xff09; throw();\u7684\u65b9\u5f0f\u89c4\u8303\u5316\u3002<\/p>\n<p>\u603b\u7ed3&#xff1a;\u5f02\u5e38\u603b\u4f53\u800c\u8a00&#xff0c;\u5229\u5927\u4e8e\u5f0a&#xff0c;\u6240\u4ee5\u5de5\u7a0b\u4e2d\u6211\u4eec\u8fd8\u662f\u9f13\u52b1\u4f7f\u7528\u5f02\u5e38\u7684\u3002\u53e6\u5916OO\u7684\u8bed\u8a00\u57fa\u672c\u90fd\u662f\u7528\u5f02\u5e38\u5904\u7406\u9519\u8bef&#xff0c;\u8fd9\u4e5f\u53ef\u4ee5\u770b\u51fa\u8fd9\u662f\u5927\u52bf\u6240\u8d8b\u3002<\/p>\n<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.6k\u6b21\uff0c\u70b9\u8d5e147\u6b21\uff0c\u6536\u85cf132\u6b21\u3002C\u8bed\u8a00\u4f20\u7edf\u7684\u9519\u8bef\u5904\u7406\u673a\u5236\u4e3b\u8981\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a\u7ec8\u6b62\u7a0b\u5e8f\u548c\u8fd4\u56de\u9519\u8bef\u7801\u3002\u8fd9\u4e24\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355\u6613\u7528\uff0c\u4f46\u5404\u81ea\u4e5f\u6709\u5176\u5c40\u9650\u6027\u548c\u7f3a\u9677\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u590d\u6742\u9519\u8bef\u6216\u5927\u89c4\u6a21\u7a0b\u5e8f\u65f6\uff0c\u5f80\u5f80\u4f1a\u5bfc\u81f4\u7ef4\u62a4\u4e0a\u7684\u56f0\u96be\u3002_c++\u81ea\u5b9a\u4e49\u8fd0\u884c\u65f6\u5f02\u5e38<\/p>\n","protected":false},"author":2,"featured_media":40908,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,190],"topic":[],"class_list":["post-40916","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/40916.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.6k\u6b21\uff0c\u70b9\u8d5e147\u6b21\uff0c\u6536\u85cf132\u6b21\u3002C\u8bed\u8a00\u4f20\u7edf\u7684\u9519\u8bef\u5904\u7406\u673a\u5236\u4e3b\u8981\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a\u7ec8\u6b62\u7a0b\u5e8f\u548c\u8fd4\u56de\u9519\u8bef\u7801\u3002\u8fd9\u4e24\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355\u6613\u7528\uff0c\u4f46\u5404\u81ea\u4e5f\u6709\u5176\u5c40\u9650\u6027\u548c\u7f3a\u9677\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u590d\u6742\u9519\u8bef\u6216\u5927\u89c4\u6a21\u7a0b\u5e8f\u65f6\uff0c\u5f80\u5f80\u4f1a\u5bfc\u81f4\u7ef4\u62a4\u4e0a\u7684\u56f0\u96be\u3002_c++\u81ea\u5b9a\u4e49\u8fd0\u884c\u65f6\u5f02\u5e38\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/40916.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-30T04:26:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337b07d72.gif\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40916.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/40916.html\",\"name\":\"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-30T04:26:37+00:00\",\"dateModified\":\"2025-05-30T04:26:37+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/40916.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/40916.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40916.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/40916.html","og_locale":"zh_CN","og_type":"article","og_title":"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb3.6k\u6b21\uff0c\u70b9\u8d5e147\u6b21\uff0c\u6536\u85cf132\u6b21\u3002C\u8bed\u8a00\u4f20\u7edf\u7684\u9519\u8bef\u5904\u7406\u673a\u5236\u4e3b\u8981\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a\u7ec8\u6b62\u7a0b\u5e8f\u548c\u8fd4\u56de\u9519\u8bef\u7801\u3002\u8fd9\u4e24\u79cd\u65b9\u5f0f\u867d\u7136\u7b80\u5355\u6613\u7528\uff0c\u4f46\u5404\u81ea\u4e5f\u6709\u5176\u5c40\u9650\u6027\u548c\u7f3a\u9677\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u590d\u6742\u9519\u8bef\u6216\u5927\u89c4\u6a21\u7a0b\u5e8f\u65f6\uff0c\u5f80\u5f80\u4f1a\u5bfc\u81f4\u7ef4\u62a4\u4e0a\u7684\u56f0\u96be\u3002_c++\u81ea\u5b9a\u4e49\u8fd0\u884c\u65f6\u5f02\u5e38","og_url":"https:\/\/www.wsisp.com\/helps\/40916.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-30T04:26:37+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530042635-6839337b07d72.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/40916.html","url":"https:\/\/www.wsisp.com\/helps\/40916.html","name":"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-30T04:26:37+00:00","dateModified":"2025-05-30T04:26:37+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/40916.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/40916.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/40916.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++ \u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0e\u81ea\u5b9a\u4e49\u5f02\u5e38\u4f53\u7cfb"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=40916"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40916\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/40908"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=40916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=40916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=40916"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=40916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}