gpt4 book ai didi

c++ - C++编译器错误,从单词中删除字母

转载 作者:行者123 更新时间:2023-12-02 10:17:31 25 4
gpt4 key购买 nike

编译器显示此错误:

error: invalid operands to binary expression ('basic_ostream<char, std::__1::char_traits<char> >' and 'void')

我究竟做错了什么?
#include <iostream>
#include <string>
using namespace std;

void remove(string x, string y)
{
while (x.find_first_of(y) != -1)
{
x.erase(x.find_first_of(y), 1);
}
}

int main()
{
string a, b;
cout << "Enter word: ";
cin >> a;
cout << "Sign: ";
cin >> b;
cout << "Result: " << remove(a, b) << endl;

return 0;
}

最佳答案

该函数不返回任何内容(即void)。所以你什么都不输出


string remove(string x,string y){
..............
return x;
}

关于c++ - C++编译器错误,从单词中删除字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61455298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com