> For the complete documentation index, see [llms.txt](https://docs.1l.lol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1l.lol/strings/bigint.md).

# 字符串比较（strcmp）

### C 风格：strcmp

```cpp
#include <cstring>
int strcmp(const char *a, const char *b);
```

按**字典序**逐字符比较：

| 返回值 | 含义     |
| --- | ------ |
| 0   | a == b |
| 正数  | a > b  |
| 负数  | a < b  |

```cpp
char a[] = "apple", b[] = "banana";
if (strcmp(a, b) < 0) cout << "a 在前";   // 成立
if (strcmp(a, a) == 0) cout << "相等";
```

返回的正/负数通常是首个不同字符的 ASCII 差值，不要依赖具体数值，只判断正负或是否为 0。

### C++ string：直接用运算符

```cpp
string a = "apple", b = "banana";
if (a < b)  cout << "a 在前";
if (a == b) cout << "相等";
if (a != b) cout << "不同";
```

`string` 重载了 `< > ==` 等，也按字典序比较，比 `strcmp` 更直观，推荐使用。

### 字典序规则

从第一个字符开始逐一比较 ASCII 值，直到出现不同或结束；一个串是另一个的前缀时，**短的更小**。例如 `"app" < "apple"`。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1l.lol/strings/bigint.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
