我想编写 c++ 代码,它将所有与输入值长度相同的元素分开
#include <iostream>
#include <vector>
using namespace std;
string database[] = {"green", "stupid", "boy", "girl", "forest", "mobile", "morning", "love", "keyboard", "incredible"};
string input;
string count(string input, string database[]){
string lengthFilter[] = {};
int inputLength = input.length();
for (int i = 0; i < database->length(); ++i){
if (database[i].length() == inputLength)
{
lengthFilter[lengthFilter->length()] = database[i];
}
}
return (lengthFilter);
}
int main()
{
cin >> input;
cout << count(input, database);
return 0;
}
但它给出了错误
main.cpp: In function 'std::__cxx11::string count(std::__cxx11::string, std::__cxx11::string*)':
main.cpp:16:22: error: could not convert 'lengthFilter' from 'std::__cxx11::string [0] {aka std::__cxx11::basic_string<char> [0]}' to 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}'
return (lengthFilter);
^
exit status 1
我找不到我的错误,请帮助我。