我想找出用户输入的字符串的任何排列是否是一个包含少量单词的文本文件中的有效单词。
在输入字符串后,什么都没有发生! "if"语句有什么问题?如果我编写了一个else语句并且被执行,这意味着控制从未到达if,即使我输入了列表.txt中存在的单词
我该尝试什么来解决这个问题?
//check if any permutation of a user inputted word are in a pre defined text file
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(){
cout<<"Enter a word to check for the presence of any
<< of its permutation in a file \n";
string word;
cin>>word;
sort(word.begin(), word.end());
vector<string> str;
do str.push_back(word);
while( next_permutation(word.begin(),word.end()) );
ifstream readFile("list.txt");
string line;
while(readFile>>line){
for (int i = 0; i < str.size(); ++i){
if(line==str[i]){
cout << "found " << str[i] << endl;
break;
}
}
}
system("pause");
return EXIT_SUCCESS;
}