Files
XCEngine/docs/api/containers/string/clear.md
ssdfasd 5c3566774b docs: 更新 containers 和 threading 模块文档
- containers: 更新 string 类的多个方法文档
- threading: 更新 mutex 和 task-group 方法文档
2026-03-26 01:59:14 +08:00

40 lines
911 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# String::Clear
```cpp
void Clear();
```
清空字符串内容,将长度设为 0但不释放已分配的内存。
**参数:**
**返回:**
**复杂度:** O(1)
**示例:**
```cpp
#include "XCEngine/Core/Containers/String.h"
#include <iostream>
int main() {
XCEngine::Containers::String s("Hello World");
std::cout << "Before clear - Length: " << s.Length()
<< ", Capacity: " << s.Capacity() << std::endl;
// 输出: Before clear - Length: 11, Capacity: 12
s.Clear();
std::cout << "After clear - Length: " << s.Length()
<< ", Capacity: " << s.Capacity() << std::endl;
// 输出: After clear - Length: 0, Capacity: 12
std::cout << "Empty: " << s.Empty() << std::endl; // 输出: Empty: 1
return 0;
}
```
## 相关文档
- [String 总览](string.md) - 返回类总览
- [Reserve / Resize](reserve-resize.md) - 内存管理