#include <iostream>
#include <string>
int main() {
    std::string str = "Hello, World!";
    // 删除从索引 5 开始的 7 个字符
    str.erase(5, 7);
    std::cout << str << std::endl;  // 输出: Hello!
    return 0;
}std::string::erase 是 C++ 标准库中 std::string 类的一个成员函数,用于删除字符串中的字符。str.erase(5, 7); 表示从索引 5 开始删除 7 个字符。索引是从 0 开始的,因此索引 5 对应的是逗号后面的空格。str 变为 "Hello!"。如果你需要更多关于 erase 函数的用法或有其他问题,请告诉我!
上一篇:c++ std::vector
下一篇:c++ #if
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站