Files
XCSDD/docs/api/containers/string/operator-plus-assign.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling
- Improve link styling with underline decoration
- Hide leaf nodes from tree, only show directories
- Fix log file path for packaged app
2026-03-19 12:44:08 +08:00

1.1 KiB

String::operator+=

String& operator+=(const String& other);
String& operator+=(const char* str);
String& operator+=(char c);

将指定的内容追加到当前 String 的末尾。

参数:

  • other - 要追加的 String 对象
  • str - 要追加的以 null 结尾的 C 字符串
  • c - 要追加的单个字符

返回: *this,支持链式调用

复杂度: O(n),其中 n 为被追加内容的长度。可能会触发重新分配,但均摊复杂度为 O(1)。

示例:

#include "XCEngine/Containers/String.h"
#include <iostream>

int main() {
    XCEngine::Containers::String s("Hello");

    s += XCEngine::Containers::String(" World");  // 追加 String
    std::cout << s.CStr() << std::endl;           // 输出: Hello World

    s += "!";                                     // 追加 const char*
    std::cout << s.CStr() << std::endl;           // 输出: Hello World!

    s += '?';                                     // 追加 char
    std::cout << s.CStr() << std::endl;           // 输出: Hello World!?

    return 0;
}

相关文档