{"id":10020721,"date":"2025-04-11T23:39:27","date_gmt":"2025-04-11T15:39:27","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020721"},"modified":"2025-04-11T23:39:27","modified_gmt":"2025-04-11T15:39:27","slug":"c%e5%9c%a8%e5%b5%8c%e5%85%a5%e5%bc%8f%e4%b8%ad%e8%a1%a8%e7%8e%b0%e5%a6%82%e4%bd%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020721","title":{"rendered":"C++\u5728\u5d4c\u5165\u5f0f\u4e2d\u8868\u73b0\u5982\u4f55\uff1f"},"content":{"rendered":"<h2>C++\u5728\u5d4c\u5165\u5f0f\u4e2d\u8868\u73b0\u5982\u4f55\uff1f<\/h2>\n<p>\u4f5c\u4e3a\u4e00\u4e2a\u4ece\u673a\u68b0\u8f6c\u884c\u5230\u5d4c\u5165\u5f0f\u5f00\u53d1\u7684\u8001\u5175\uff0c\u6211\u6df1\u6df1\u4f53\u4f1a\u5230\u4e86C++\u5728\u5d4c\u5165\u5f0f\u9886\u57df\u7684\u72ec\u7279\u9b45\u529b\u4e0e\u6311\u6218\u3002\u4ece\u6700\u521d\u5728\u53a6\u95e8\u67d0\u9a6c\u5199\u5355\u7247\u673a\u4ee3\u7801\u65f6\u7684\u7eafC\u8bed\u8a00\uff0c\u5230\u540e\u6765\u5728\u4e16\u754c500\u5f3a\u5916\u4f01\u5f00\u53d1\u6c7d\u8f66\u7535\u5b50\u9879\u76ee\u65f6\u5927\u91cf\u4f7f\u7528C++\uff0c\u8fd9\u4e9b\u5e74\u7684\u7ecf\u5386\u8ba9\u6211\u5bf9\u8fd9\u4e2a\u8bdd\u9898\u6709\u5f88\u591a\u601d\u8003\u3002<\/p>\n<p>\u6700\u8fd1\u6211\u5728\u5f55\u5236<a href=\"https:\/\/link.segmentfault.com\/?enc=YTYqyI6J8ZQysc4kFe6tCg%3D%3D.dIPlQNOPERQqxlD9EeyIw8XbJB9a1mpaljvXnGSjEnIBwXd%2B%2FQ54ETplwNFIQ3JJ\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u300aSTM32\u5b9e\u6218\u5feb\u901f\u5165\u95e8\u300b\uff08\u70b9\u51fb\u76f4\u8fbe\uff09<\/a>\u8bfe\u7a0b\u65f6\uff0c\u5b66\u5458\u7ecf\u5e38\u95ee\u6211\uff1a&#8221;\u8001\u5e08\uff0cSTM32\u5f00\u53d1\u5230\u5e95\u8be5\u7528C\u8fd8\u662fC++\uff1f&#8221;\u8fd9\u4e2a\u95ee\u9898\u503c\u5f97\u597d\u597d\u804a\u804a\u3002\u867d\u7136\u6211\u7684\u8bfe\u7a0b\u4e3b\u8981\u4f7f\u7528C\u8bed\u8a00\uff08\u8003\u8651\u5230\u5165\u95e8\u5b66\u4e60\u66f2\u7ebf\uff09\uff0c\u4f46\u5728\u8bfe\u7a0b\u7684\u8fdb\u9636\u90e8\u5206\uff0c\u6211\u4e5f\u4e13\u95e8\u8bb2\u89e3\u4e86\u5982\u4f55\u5728STM32\u9879\u76ee\u4e2d\u4f18\u96c5\u5730\u4f7f\u7528C++\u7279\u6027\u3002<\/p>\n<h3>\u4e00\u3001C++\u5728\u5d4c\u5165\u5f0f\u4e2d\u7684\u4f18\u52bf<\/h3>\n<h4>1. \u66f4\u597d\u7684\u4ee3\u7801\u7ec4\u7ec7\u80fd\u529b<\/h4>\n<p>\u8fd8\u8bb0\u5f97\u6211\u521a\u5f00\u59cb\u7528\u7eafC\u8bed\u8a00\u5f00\u53d1\u5355\u7247\u673a\u9879\u76ee\u65f6\uff0c\u4ee3\u7801\u7ec4\u7ec7\u771f\u662f\u4e00\u56e2\u7cdf\u3002\u5404\u79cd\u5168\u5c40\u53d8\u91cf\u6ee1\u5929\u98de\uff0c\u51fd\u6570\u4e4b\u95f4\u7684\u5173\u7cfb\u9519\u7efc\u590d\u6742\uff0c\u7ef4\u62a4\u8d77\u6765\u7b80\u76f4\u662f\u5669\u68a6\u3002<\/p>\n<p>\u540e\u6765\u5728\u5916\u4f01\u505a\u6c7d\u8f66\u7535\u5b50\u9879\u76ee\uff0c\u4f7f\u7528C++\u540e\uff0c\u8fd9\u4e9b\u95ee\u9898\u5f97\u5230\u4e86\u4f18\u96c5\u7684\u89e3\u51b3\uff1a<\/p>\n<pre><code class=\"cpp\">class TemperatureSensor {\nprivate:\n    float currentTemp;\n    const int PIN_ADC;\n    \npublic:\n    TemperatureSensor(int pin) : PIN_ADC(pin) {}\n    \n    float readTemperature() {\n        \/\/ \u8bfb\u53d6\u6e29\u5ea6\u903b\u8f91\n    }\n    \n    void calibrate() {\n        \/\/ \u6821\u51c6\u903b\u8f91\n    }\n};<\/code><\/pre>\n<p>\u8fd9\u6837\u7684\u9762\u5411\u5bf9\u8c61\u8bbe\u8ba1\uff0c\u8ba9\u4ee3\u7801\u7ed3\u6784\u6e05\u6670\u4e86\u5f88\u591a\u3002\u76f8\u5173\u7684\u6570\u636e\u548c\u65b9\u6cd5\u88ab\u5f88\u597d\u5730\u5c01\u88c5\u5728\u4e00\u8d77\uff0c\u4e0d\u7528\u518d\u62c5\u5fc3\u5168\u5c40\u53d8\u91cf\u6c61\u67d3\u7684\u95ee\u9898\u3002<\/p>\n<h4>2. \u66f4\u5f3a\u7684\u7c7b\u578b\u5b89\u5168<\/h4>\n<p>C++\u7684\u7c7b\u578b\u7cfb\u7edf\u6bd4C\u8981\u5f3a\u5927\u5f97\u591a\u3002\u8bb0\u5f97\u6709\u4e00\u6b21\uff0c\u6211\u4eec\u9879\u76ee\u4e2d\u51fa\u73b0\u4e86\u4e00\u4e2a\u8be1\u5f02\u7684bug\uff0c\u82b1\u4e86\u4e09\u5929\u624d\u53d1\u73b0\u662fC\u8bed\u8a00\u4e2d\u7684\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u5bfc\u81f4\u7684\u3002\u5982\u679c\u5f53\u65f6\u7528\u7684\u662fC++\uff0c\u7f16\u8bd1\u5668\u5c31\u4f1a\u7ed9\u51fa\u8b66\u544a\u3002<\/p>\n<pre><code class=\"cpp\">enum class SensorType {\n    TEMPERATURE,\n    HUMIDITY,\n    PRESSURE\n};\n\n\/\/ \u7f16\u8bd1\u5668\u4f1a\u5f3a\u5236\u7c7b\u578b\u68c0\u67e5\uff0c\u907f\u514d\u9519\u8bef\u4f7f\u7528\nvoid processSensor(SensorType type) {\n    switch(type) {\n        case SensorType::TEMPERATURE:\n            \/\/ \u5904\u7406\u6e29\u5ea6\u4f20\u611f\u5668\n            break;\n        \/\/ ...\n    }\n}<\/code><\/pre>\n<h4>3. \u6a21\u677f\u5e26\u6765\u7684\u7075\u6d3b\u6027<\/h4>\n<p>\u6a21\u677f\u662fC++\u6700\u5f3a\u5927\u7684\u7279\u6027\u4e4b\u4e00\uff0c\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\u4e5f\u80fd\u53d1\u6325\u91cd\u8981\u4f5c\u7528\uff1a<\/p>\n<pre><code class=\"cpp\">template&lt;typename T, size_t SIZE&gt;\nclass CircularBuffer {\nprivate:\n    T buffer[SIZE];\n    size_t head = 0;\n    size_t tail = 0;\n    \npublic:\n    bool push(T value) {\n        \/\/ \u5b9e\u73b0\u5faa\u73af\u7f13\u51b2\u533a\u903b\u8f91\n    }\n    \n    T pop() {\n        \/\/ \u5b9e\u73b0\u6570\u636e\u8bfb\u53d6\u903b\u8f91\n    }\n};\n\n\/\/ \u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u4e0d\u540c\u7c7b\u578b\u548c\u5927\u5c0f\u7684\u7f13\u51b2\u533a\nCircularBuffer&lt;uint16_t, 64&gt; adcBuffer;\nCircularBuffer&lt;float, 32&gt; filterBuffer;<\/code><\/pre>\n<h4>4. RAII\u673a\u5236\u7684\u8d44\u6e90\u7ba1\u7406<\/h4>\n<p>\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\uff0c\u8d44\u6e90\u7ba1\u7406\u5f02\u5e38\u91cd\u8981\u3002C++\u7684RAII\uff08Resource Acquisition Is Initialization\uff09\u673a\u5236\u63d0\u4f9b\u4e86\u4f18\u96c5\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<pre><code class=\"cpp\">class SPIMutexGuard {\nprivate:\n    SPI_TypeDef* spi;\n    \npublic:\n    SPIMutexGuard(SPI_TypeDef* _spi) : spi(_spi) {\n        \/\/ \u83b7\u53d6SPI\u603b\u7ebf\u8bbf\u95ee\u6743\n        lockSPI(spi);\n    }\n    \n    ~SPIMutexGuard() {\n        \/\/ \u81ea\u52a8\u91ca\u653eSPI\u603b\u7ebf\n        unlockSPI(spi);\n    }\n};<\/code><\/pre>\n<h3>\u4e8c\u3001C++\u5728\u5d4c\u5165\u5f0f\u4e2d\u7684\u6311\u6218<\/h3>\n<h4>1. \u8d44\u6e90\u5f00\u9500\u95ee\u9898<\/h4>\n<p>\u8fd9\u53ef\u80fd\u662f\u6700\u53d7\u4e89\u8bae\u7684\u95ee\u9898\u3002\u5f88\u591a\u4eba\u8ba4\u4e3aC++\u4f1a\u5e26\u6765\u989d\u5916\u7684\u5f00\u9500\uff0c\u5c24\u5176\u662f\u5728\u8d44\u6e90\u53d7\u9650\u7684MCU\u4e0a\u3002\u4f46\u5b9e\u9645\u60c5\u51b5\u662f\uff1a<\/p>\n<ol>\n<li>\u865a\u51fd\u6570\u8868\u786e\u5b9e\u4f1a\u5360\u7528\u4e00\u4e9bROM\u7a7a\u95f4\uff0c\u4f46\u901a\u5e38\u662f\u53ef\u4ee5\u63a5\u53d7\u7684\u3002<\/li>\n<li>\u6a21\u677f\u5c55\u5f00\u53ef\u80fd\u589e\u52a0\u4ee3\u7801\u4f53\u79ef\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u8c28\u614e\u4f7f\u7528\u6765\u63a7\u5236\u3002<\/li>\n<li>\u5f02\u5e38\u5904\u7406\u673a\u5236\u5982\u679c\u4e0d\u4f7f\u7528\uff0c\u7f16\u8bd1\u5668\u4e0d\u4f1a\u751f\u6210\u76f8\u5173\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<h4>2. \u5b9e\u65f6\u6027\u8981\u6c42<\/h4>\n<p>\u5728\u9ad8\u5b9e\u65f6\u6027\u8981\u6c42\u7684\u573a\u666f\u4e0b\uff0cC++\u7684\u67d0\u4e9b\u7279\u6027\u786e\u5b9e\u9700\u8981\u8c28\u614e\u4f7f\u7528\uff1a<\/p>\n<ol>\n<li>\u52a8\u6001\u5185\u5b58\u5206\u914d\u8981\u907f\u514d<\/li>\n<li>\u865a\u51fd\u6570\u8c03\u7528\u5728\u5173\u952e\u8def\u5f84\u4e0a\u8981\u8c28\u614e<\/li>\n<li>\u5f02\u5e38\u5904\u7406\u673a\u5236\u6700\u597d\u4e0d\u7528<\/li>\n<\/ol>\n<p>\u4f46\u8fd9\u4e0d\u610f\u5473\u7740\u8981\u5b8c\u5168\u653e\u5f03C++\uff0c\u800c\u662f\u8981\u6839\u636e\u5b9e\u9645\u9700\u6c42\u5408\u7406\u4f7f\u7528\u5176\u7279\u6027\u3002<\/p>\n<h4>3. \u5f00\u53d1\u56e2\u961f\u9002\u5e94\u6027<\/h4>\n<p>\u8fd9\u662f\u4e00\u4e2a\u73b0\u5b9e\u95ee\u9898\u3002\u6211\u5728\u5916\u4f01\u5de5\u4f5c\u65f6\u5c31\u9047\u5230\u8fc7\uff1a\u56e2\u961f\u91cc\u6709\u4e9b\u8001\u5de5\u7a0b\u5e08\u5bf9C++\u6bd4\u8f83\u62b5\u89e6\uff0c\u89c9\u5f97&#8221;C\u8bed\u8a00\u591f\u7528\u4e86\uff0c\u4e3a\u4ec0\u4e48\u8981\u7528C++&#8221;\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\u662f\u6e10\u8fdb\u5f0f\u5f15\u5165\uff1a<\/p>\n<ol>\n<li>\u5148\u4f7f\u7528\u7c7b\u7684\u5c01\u88c5\u7279\u6027<\/li>\n<li>\u518d\u5f15\u5165\u7b80\u5355\u7684\u7ee7\u627f<\/li>\n<li>\u6700\u540e\u624d\u8003\u8651\u66f4\u590d\u6742\u7684\u7279\u6027<\/li>\n<\/ol>\n<h3>\u4e09\u3001\u6700\u4f73\u5b9e\u8df5\u5efa\u8bae<\/h3>\n<h4>1. \u5408\u7406\u4f7f\u7528C++\u7279\u6027<\/h4>\n<p>\u4e0d\u662f\u6240\u6709C++\u7279\u6027\u90fd\u9002\u5408\u5d4c\u5165\u5f0f\u5f00\u53d1\u3002\u6211\u7684\u5efa\u8bae\u662f\uff1a<\/p>\n<ul>\n<li>\n<p>\u63a8\u8350\u4f7f\u7528\uff1a<\/p>\n<ul>\n<li>\u7c7b\u7684\u5c01\u88c5<\/li>\n<li>const\u6b63\u786e\u6027<\/li>\n<li>\u5f15\u7528\u53c2\u6570<\/li>\n<li>\u7b80\u5355\u7684\u7ee7\u627f<\/li>\n<li>\u9759\u6001\u591a\u6001<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8c28\u614e\u4f7f\u7528\uff1a<\/p>\n<ul>\n<li>\u865a\u51fd\u6570<\/li>\n<li>\u6a21\u677f\uff08\u9650\u5236\u6df1\u5ea6\uff09<\/li>\n<li>\u8fd0\u7b97\u7b26\u91cd\u8f7d<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u907f\u514d\u4f7f\u7528\uff1a<\/p>\n<ul>\n<li>\u5f02\u5e38\u5904\u7406<\/li>\n<li>\u52a8\u6001\u5185\u5b58\u5206\u914d<\/li>\n<li>STL\uff08\u9664\u975e\u6709\u7279\u6b8a\u4f18\u5316\u7684\u5b9e\u73b0\uff09<\/li>\n<li>RTTI<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2. \u5185\u5b58\u7ba1\u7406\u7b56\u7565<\/h4>\n<p>\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\uff0c\u5185\u5b58\u7ba1\u7406\u5f02\u5e38\u91cd\u8981\u3002\u6211\u5efa\u8bae\uff1a<\/p>\n<ol>\n<li>\n<p>\u4f7f\u7528\u9759\u6001\u5185\u5b58\u5206\u914d<\/p>\n<pre><code class=\"cpp\">\/\/ \u4e0d\u8981\u8fd9\u6837\nclass BadExample {\n uint8_t* buffer = new uint8_t[1024];  \/\/ \u5371\u9669\uff01\n};\n\n\/\/ \u5e94\u8be5\u8fd9\u6837\nclass GoodExample {\n static constexpr size_t BUFFER_SIZE = 1024;\n uint8_t buffer[BUFFER_SIZE];\n};<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5982\u679c\u5fc5\u987b\u4f7f\u7528\u52a8\u6001\u5185\u5b58\uff0c\u8003\u8651\u4f7f\u7528\u5185\u5b58\u6c60<\/p>\n<pre><code class=\"cpp\">template&lt;typename T, size_t POOL_SIZE&gt;\nclass MemoryPool {\n \/\/ \u5b9e\u73b0\u56fa\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u6c60\n};<\/code><\/pre>\n<\/li>\n<\/ol>\n<h4>3. \u4e2d\u65ad\u5904\u7406<\/h4>\n<p>\u5728\u4e2d\u65ad\u5904\u7406\u4e2d\u8981\u7279\u522b\u5c0f\u5fc3C++\u7279\u6027\u7684\u4f7f\u7528\uff1a<\/p>\n<ol>\n<li>\u4e2d\u65ad\u5904\u7406\u51fd\u6570\u5e94\u8be5\u4fdd\u6301\u7b80\u5355<\/li>\n<li>\u907f\u514d\u5728\u4e2d\u65ad\u4e2d\u8c03\u7528\u865a\u51fd\u6570<\/li>\n<li>\u4e0d\u8981\u5728\u4e2d\u65ad\u4e2d\u4f7f\u7528RAII\u5bf9\u8c61<\/li>\n<\/ol>\n<h4>4. \u4ee3\u7801\u4f18\u5316\u7b56\u7565<\/h4>\n<ol>\n<li>\n<p>\u4f7f\u7528inline\u51fd\u6570\u66ff\u4ee3\u5b8f<\/p>\n<pre><code class=\"cpp\">\/\/ \u4e0d\u597d\u7684\u65b9\u5f0f\n#define MAX(a,b) ((a) &gt; (b) ? (a) : (b))\n\n\/\/ \u66f4\u597d\u7684\u65b9\u5f0f\ntemplate&lt;typename T&gt;\ninline T max(T a, T b) {\n return a &gt; b ? a : b;\n}<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5229\u7528\u7f16\u8bd1\u671f\u8ba1\u7b97<\/p>\n<pre><code class=\"cpp\">constexpr uint32_t calculateTimerPeriod(uint32_t frequency) {\n return SystemCoreClock \/ frequency - 1;\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>\u56db\u3001\u5b9e\u9645\u9879\u76ee\u6848\u4f8b<\/h3>\n<p>\u8ba9\u6211\u5206\u4eab\u4e00\u4e2a\u771f\u5b9e\u7684\u9879\u76ee\u7ecf\u9a8c\u3002\u5728\u4e00\u4e2a\u6c7d\u8f66\u7535\u5b50\u9879\u76ee\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5904\u7406\u591a\u4e2a\u4f20\u611f\u5668\u7684\u6570\u636e\u3002\u6700\u521d\u7528C\u8bed\u8a00\u5b9e\u73b0\u65f6\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code class=\"c\">struct sensor_data {\n    float temperature;\n    float pressure;\n    float humidity;\n};\n\nvoid process_temperature(struct sensor_data* data);\nvoid process_pressure(struct sensor_data* data);\nvoid process_humidity(struct sensor_data* data);<\/code><\/pre>\n<p>\u540e\u6765\u91cd\u6784\u6210C++\u7248\u672c\uff1a<\/p>\n<pre><code class=\"cpp\">class SensorBase {\npublic:\n    virtual void process() = 0;\n    virtual ~SensorBase() = default;\nprotected:\n    float value;\n};\n\nclass TemperatureSensor : public SensorBase {\npublic:\n    void process() override {\n        \/\/ \u6e29\u5ea6\u5904\u7406\u903b\u8f91\n    }\n};\n\n\/\/ \u5176\u4ed6\u4f20\u611f\u5668\u7c7b\u4f3c<\/code><\/pre>\n<p>\u8fd9\u6837\u7684\u6539\u9020\u5e26\u6765\u4e86\u51e0\u4e2a\u660e\u663e\u7684\u597d\u5904\uff1a<\/p>\n<ol>\n<li>\u4ee3\u7801\u66f4\u5bb9\u6613\u6269\u5c55\uff0c\u6dfb\u52a0\u65b0\u7684\u4f20\u611f\u5668\u7c7b\u578b\u5f88\u65b9\u4fbf<\/li>\n<li>\u6570\u636e\u548c\u5904\u7406\u903b\u8f91\u88ab\u5f88\u597d\u5730\u5c01\u88c5<\/li>\n<li>\u63a5\u53e3\u66f4\u6e05\u6670\uff0c\u4e0d\u5bb9\u6613\u51fa\u9519<\/li>\n<\/ol>\n<h3>\u4e94\u3001\u672a\u6765\u5c55\u671b<\/h3>\n<p>\u968f\u7740MCU\u6027\u80fd\u7684\u63d0\u5347\uff0cC++\u5728\u5d4c\u5165\u5f0f\u9886\u57df\u7684\u5e94\u7528\u4f1a\u8d8a\u6765\u8d8a\u5e7f\u6cdb\u3002\u7279\u522b\u662f\u5728\u4ee5\u4e0b\u65b9\u9762\uff1a<\/p>\n<ol>\n<li>\u7269\u8054\u7f51\u8bbe\u5907<\/li>\n<li>\u667a\u80fd\u5bb6\u7535<\/li>\n<li>\u6c7d\u8f66\u7535\u5b50<\/li>\n<li>\u5de5\u4e1a\u63a7\u5236<\/li>\n<\/ol>\n<h3>\u7ed3\u8bed<\/h3>\n<p>C++\u5728\u5d4c\u5165\u5f0f\u5f00\u53d1\u4e2d\u662f\u628a\u53cc\u5203\u5251\uff0c\u5173\u952e\u662f\u8981\u7528\u5bf9\u5730\u65b9\uff0c\u7528\u5bf9\u65b9\u5f0f\u3002\u5b83\u80fd\u5e26\u6765\u66f4\u597d\u7684\u4ee3\u7801\u7ec4\u7ec7\u3001\u66f4\u5f3a\u7684\u7c7b\u578b\u5b89\u5168\u6027\uff0c\u4f46\u540c\u65f6\u4e5f\u9700\u8981\u6211\u4eec\u8b66\u60d5\u5176\u53ef\u80fd\u5e26\u6765\u7684\u5f00\u9500\u3002<\/p>\n<p>\u7ecf\u8fc7\u8fd9\u4e9b\u5e74\u7684\u5b9e\u8df5\uff0c\u6211\u7684\u5efa\u8bae\u662f\uff1a\u5bf9\u4e8e\u8d44\u6e90\u975e\u5e38\u53d7\u9650\u7684\u5c0f\u578bMCU\u9879\u76ee\uff0c\u8fd8\u662f\u4e3b\u8981\u4f7f\u7528C\u8bed\u8a00\uff1b\u4f46\u5bf9\u4e8e\u8f83\u5927\u7684\u9879\u76ee\uff0c\u7279\u522b\u662f\u9700\u8981\u826f\u597d\u4ee3\u7801\u7ec4\u7ec7\u7684\u573a\u5408\uff0cC++\u662f\u5f88\u597d\u7684\u9009\u62e9\u3002<\/p>\n<p>\u6700\u540e\uff0c\u4e0d\u7ba1\u9009\u62e9C\u8fd8\u662fC++\uff0c\u5173\u952e\u662f\u8981\u7406\u89e3\u5e95\u5c42\u539f\u7406\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u5728\u6211\u7684<a href=\"https:\/\/link.segmentfault.com\/?enc=wew2XNhOJzc1h4Mw6EtClg%3D%3D.BHjF1P6BiE7Q9e0Oa7Dx8q%2FUz%2Bb9LK6njHVAflKljtSV8cb8rnGhqGfO7AgIriPu\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u300aSTM32\u5b9e\u6218\u5feb\u901f\u5165\u95e8\u300b\uff08\u70b9\u51fb\u76f4\u8fbe\uff09<\/a>\u8bfe\u7a0b\u4e2d\uff0c\u6211\u7279\u522b\u5f3a\u8c03\u4e86\u5e95\u5c42\u539f\u7406\u7684\u91cd\u8981\u6027\uff0c\u56e0\u4e3a\u53ea\u6709\u771f\u6b63\u7406\u89e3\u4e86\u539f\u7406\uff0c\u624d\u80fd\u505a\u51fa\u6700\u9002\u5408\u9879\u76ee\u7684\u6280\u672f\u9009\u62e9\u3002<\/p>\n<hr>\n<p><strong>\u53e6\u5916\uff0c\u60f3\u8fdb\u5927\u5382\u7684\u540c\u5b66\uff0c\u4e00\u5b9a\u8981\u597d\u597d\u5b66\u7b97\u6cd5\uff0c\u8fd9\u662f\u9762\u8bd5\u5fc5\u5907\u7684\u3002\u8fd9\u91cc\u51c6\u5907\u4e86\u4e00\u4efd BAT \u5927\u4f6c\u603b\u7ed3\u7684 LeetCode \u5237\u9898\u5b9d\u5178\uff0c\u5f88\u591a\u4eba\u9760\u5b83\u4eec\u8fdb\u4e86\u5927\u5382\u3002<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"286\" height=\"83\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaCCY\" alt=\"\" title=\"\"><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=dYPRjMfpqMLASpn3mJbwRQ%3D%3D.uhwd0IJH4jBXX%2BvaoMqrYfGOvTB3%2FV0YxvoL39We63lwopuwhuilY94tlCZHss8l\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u5237\u9898 | LeetCode\u7b97\u6cd5\u5237\u9898\u795e\u5668\uff0c\u770b\u5b8c BAT \u968f\u4f60\u6311\uff01<\/a><\/p>\n<h4>\u6709\u6536\u83b7\uff1f\u5e0c\u671b\u8001\u94c1\u4eec\u6765\u4e2a\u4e09\u8fde\u51fb\uff0c\u7ed9\u66f4\u591a\u7684\u4eba\u770b\u5230\u8fd9\u7bc7\u6587\u7ae0<\/h4>\n<p><strong>\u63a8\u8350\u9605\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=EC4MOPV63dy1YXXFjyh0Fg%3D%3D.nDBnXRUA10FE9oFqiZnLUPBwWzKYkmCy9FKgox1utNuu31nHK%2BEKVfrDH9sEXZUg\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u3010\u826f\u8bb8\u5b66\u5802\u30112025\u5e74\u5d4c\u5165\u5f0f\u5982\u4f55\u9ad8\u85aa\u5165\u884c\uff1f<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=DAFpmNsa%2FD%2BqsqfJvuYFGg%3D%3D.CBuZT7%2Fl%2FDuo2QOjA7AhIQgNmzwFPeK4sll1mHCd4lDKKjcAGgTIoIWTYvupTV%2Fd\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u7f16\u7a0b\u8d44\u6599\u5927\u5168<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=oTaymBf%2BgObnAQo0QW5Hxg%3D%3D.A24OmUEoFp6ZyYjcsQ%2FUAA7FxhuBjvQlVRZomLeUKhL23A1RnxiKYVd4MmP3wDWb\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u8f6f\u4ef6\u8d44\u6e90<\/a><\/li>\n<\/ul>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u535a\u5ba2\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=unRxxRP6DNZzXqgHfJmvvA%3D%3D.a%2BPfUY185NSrFh2ntoupdbcSHxNCofxdaj31XxOMpQo%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u826f\u8bb8\u5d4c\u5165\u5f0f\u6559\u7a0b\u7f51<\/a>\uff0c\u6ee1\u6ee1\u90fd\u662f\u5e72\u8d27\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046439638\">https:\/\/segmentfault.com\/a\/1190000046439638<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++\u5728\u5d4c\u5165\u5f0f\u4e2d\u8868\u73b0\u5982\u4f55\uff1f \u4f5c\u4e3a\u4e00\u4e2a\u4ece\u673a\u68b0\u8f6c\u884c\u5230\u5d4c\u5165\u5f0f\u5f00\u53d1\u7684\u8001\u5175\uff0c\u6211\u6df1\u6df1\u4f53\u4f1a\u5230\u4e86C++\u5728\u5d4c\u5165\u5f0f\u9886\u57df\u7684\u72ec\u7279\u9b45\u529b\u4e0e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020721","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020721"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020721\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}