这段 C++ 测试代码用于从字符串中删除特定字母:
/* remove l from string */
my_str.erase(remove(my_str.begin(), my_str.end(), 'l'), my_str.end());
在cpp.sh编译器上正确编译和执行,但在OnlineGDB编译器上失败。
string.erase() 和 remove() 重载函数仅在 OnlineGDB 编译器上因参数不兼容而失败。为什么?
需要为 OnlineGDB 明确添加:
#include <algorithm>