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/