C++ 编译器差异 - 字符串重载函数在一个编译器上失败,但在其他编译器上工作正常

问题描述 投票:0回答:1

这段 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 编译器上因参数不兼容而失败。为什么?

c++ string compiler-errors
1个回答
0
投票

需要为 OnlineGDB 明确添加:

#include <algorithm>

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.