Files
XCEngine/docs/api/containers/string/cstr.md

37 lines
691 B
Markdown
Raw Normal View History

# String::CStr
```cpp
const char* CStr() const;
```
返回指向以 null 结尾的 C 字符串的指针。
**参数:** 无
**返回:** 指向内部字符数组的指针,以 null 结尾
**复杂度:** O(1)
**示例:**
```cpp
#include "XCEngine/Core/Containers/String.h"
#include <iostream>
#include <cstring>
int main() {
XCEngine::Containers::String s("Hello World");
const char* cstr = s.CStr();
std::cout << cstr << std::endl; // 输出: Hello World
std::cout << "Length: " << std::strlen(cstr) << std::endl; // 输出: Length: 11
return 0;
}
```
## 相关文档
- [String 总览](string.md) - 返回类总览
- [Length](size.md) - 获取长度