首页 > 解决方案 > 没有重载函数的实例与参数列表匹配

问题描述

错误:

E0304   no instance of overloaded function "strstr" matches the argument 
list    testtranslator  
E0304   no instance of overloaded function "strstr" matches the argument 
list    testtranslator  
E0167   argument of type "const char **" is incompatible with parameter of 
type "const char *" testtranslator
C2665   'strstr': none of the 2 overloads could convert all the argument 
types   testtranslator  
C2665   'strstr': none of the 2 overloads could convert all the argument 
types   testtranslator  
C2664   'size_t strlen(const char *)': cannot convert argument 1 from 'const 
char *[2]' to 'const char *'

我对编程很陌生,但我必须在后天编写这个英法文本翻译器。它必须用给定的单词或短语替换单词......我的文字是以下“你好”、“什么”和“你好吗?” 我需要把它翻译成“Salut”、“Comment vas-tu?” 我不知道如何处理这些错误,我将非常感谢您的帮助。

先感谢您!

标签: c

解决方案


您正在尝试const char**作为word参数传递,而我猜您的想法是传递const char*. 看起来您需要从word数组中选择特定的单词,如下所示:

strstr(string, word[0])

因为您最近已将其声明为:

const char *word[] = {
    "hello", 
    "what"
};

而且,顺便说一句,重命名wordwordsand 可能会阻止你进一步混淆。


推荐阅读