c++ - string::erase(0) 在空字符串上?

标签 c++ string erase

std::string::erase(0) 的行为是否在空字符串上明确定义。因为cppreference说:

Removes count characters starting at index.

但对于空字符串,索引为0的字符不存在。

最佳答案

似乎没问题,因为字符串的大小是0 :

21.4.6.5 basic_string::erase [string::erase]

basic_string<charT,traits,Allocator>& erase(size_type pos = 0, size_type n = npos);

1 Requires: pos <= size()

2 Throws: out_of_range if pos > size().

关于c++ - string::erase(0) 在空字符串上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17762589/

相关文章:

vba - 如何删除包含对象和数字的多维变量数组

在 std::list 上使用删除时的 C++ 分段

c++ - GetOpenFileName 触发断点

Javascript:使用通配符和替换方法

c++ - 当我在 C++ 中删除我的 vector 时,我遇到了双重错误

c - 将具有未知数量元素的字符串扫描到 C 中的 int 数组

regex - 在 Bash 中使用 2 个不同的分隔符拆分字符串

c++ - 如何将 time_t 插入 PostgreSQL 时间戳字段

c++ - 为什么 `using`关键字不能用于静态类成员?

c++ - 将大图加载到QT窗口中并能流畅地放大和缩小