为什么我得到' replace '没有在这个范围错误中声明

why i got ‘replace’ was not declared in this scope error?

本文关键字:范围 声明 错误 replace 为什么      更新时间:2023-10-16

我想为我的代码使用替换来检测回文,这是它的一部分

cout<<isPalindrome("Won't I panic in a pit now?")<<endl;
bool PalindromeFinder::isPalindrome(string input){
    char chars[] = {' ' , ''' , '?' , '!' , ','};
    for (int i=0; i<input.length(); i++) {
        replace(input.begin(), input.end(), chars[i], '');

    }

它给我正确的结果是wontipanicinapitnow

但是当我运行函数时,它给了我' replace '没有在这个范围内声明。任何建议吗?

你没有写#include <algorithm>,也没有写std::replace

文档是你的朋友。