Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从字典中筛选出只匹配单词的排列_C++ - Fatal编程技术网

C++ 从字典中筛选出只匹配单词的排列

C++ 从字典中筛选出只匹配单词的排列,c++,C++,我有以下方法,它列出了用户输入的所有可能排列: 此代码的输出将是单词god(单词在字典中) 我的目标是过滤掉与我的字典中的单词不匹配的结果 dog god 如何做到这一点?我认为这应该很好: do { if (searchWord(input)) { cout << input << endl; } } while (next_permutation(input.begin(), input.end())); do{ if(搜索词(输入)){ cout

我有以下方法,它列出了用户输入的所有可能排列:

此代码的输出将是单词god(单词在字典中)

我的目标是过滤掉与我的字典中的单词不匹配的结果

dog
god

如何做到这一点?

我认为这应该很好:

do {
  if (searchWord(input)) {
    cout << input << endl;
  }
} while (next_permutation(input.begin(), input.end()));
do{
if(搜索词(输入)){

cout@user2881555调试告诉了你什么?为什么
searchWord()
如果单词在字典中,则返回空指针?如果用户输入的单词不在字典中,则返回空指针。它可以很好地编译,但当我输入单词并进行搜索时,它不会打印排列。@user2881555我的意思是,当您使用调试器并进入
searchWord(输入)时
输入
到达字典中的某个值时,为什么返回null?此调试告诉了您什么?@user2881555您声称
“dog”
“god”
在字典中。查看您在ideone上的代码,
字典::searchWord()如果单词存在,则
应返回一个非空指针。为什么当
输入
到达排列时
“god”和
“dog”
会返回空指针?或者它们不在字典中(正如您声称的那样),或者函数没有返回它应该返回的内容。找出原因。这是基本的调试,真的。我100%确定这些词存在。所以返回时一定是错误的?
do {
  if (searchWord(input)) {
    cout << input << endl;
  }
} while (next_permutation(input.begin(), input.end()));