I'm getting the above error in stl_algo.h and can't pinpoint the problem as I'm a beginner and there are so many vectors involved.
The overall program is meant to solve/complement the app "Just 2 Words": given an allowed word list, a string of allowed letters, and the length of one of the words, find all possible 2-word combinations that can be created from the allowed letters. The details are tedious but below is the problem function.
Excuse the horrible naming and erratic iteration - I'm still trying to learn when it's better or worse to auto-iterate over vectors and how the iterator can or can't be used within the loop (that may be what's causing the error).
vector<string> two_words(vector<string> &subsets, vector<string> &wordlist, string &letters)
{
vector<string> permutations;
vector<string> first_words;
for (auto str: subsets)
sort(str.begin(), str.end());
for (unsigned i=0;i < subsets.size(); i++) {
do {
permutations.push_back(subsets[i]);}
while (next_permutation(begin(subsets[i]), end(subsets[i])));
}
for (unsigned i = 0; i < permutations.size(); i++) {
if (find(wordlist.begin(), wordlist.end(), permutations[i]) != wordlist.end())
first_words.push_back(permutations[i]);
}
vector<string> complement_sets;
vector<string> complement_permutations;
vector<string> second_words;
for (auto str: subsets)
set_difference(str.begin(), str.end(), letters.begin(), letters.end(), back_inserter(complement_sets));
for (auto str: complement_sets) {
do {
complement_permutations.push_back(str);}
while (next_permutation(begin(str), end(str)));
}
for (unsigned i = 0; i < complement_permutations.size(); i++) {
if (find(wordlist.begin(), wordlist.end(), complement_permutations[i]) != wordlist.end())
second_words.push_back(permutations[i]);
}
vector <string> final_solutions;
string k;
for(unsigned i = 0; i < first_words.size(); i++) {
for(unsigned j = 0; j < second_words.size(); j++) {
k = first_words[i] + second_words[j];
final_solutions.push_back(k);
second_words.erase(second_words.begin()+j);
}
}
return final_solutions;
}
Error: error: invalid user-defined conversion from ‘char’ to ‘std::vector<std::basic_string<char>
Aucun commentaire:
Enregistrer un commentaire