Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.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++比较陌生,当试图比较两个字符时,遇到了一个问题,这里有个例子: #define PartOne "He" #define PartTwo "llo" char Final1Var[] = PartOne PartTwo; char ComapreVars[] = "Hello"; if(Final1Var == ComapreVars)//This is were the problem occurs, the chars are supposed to be equal to each other BUT for some reason the 'if' statement ends up determining they're not? InGameDialog::Alert("They Match"); else InGameDialog::Alert("They Don't Match");_C++ - Fatal编程技术网

比较字符? 我对C++比较陌生,当试图比较两个字符时,遇到了一个问题,这里有个例子: #define PartOne "He" #define PartTwo "llo" char Final1Var[] = PartOne PartTwo; char ComapreVars[] = "Hello"; if(Final1Var == ComapreVars)//This is were the problem occurs, the chars are supposed to be equal to each other BUT for some reason the 'if' statement ends up determining they're not? InGameDialog::Alert("They Match"); else InGameDialog::Alert("They Don't Match");

比较字符? 我对C++比较陌生,当试图比较两个字符时,遇到了一个问题,这里有个例子: #define PartOne "He" #define PartTwo "llo" char Final1Var[] = PartOne PartTwo; char ComapreVars[] = "Hello"; if(Final1Var == ComapreVars)//This is were the problem occurs, the chars are supposed to be equal to each other BUT for some reason the 'if' statement ends up determining they're not? InGameDialog::Alert("They Match"); else InGameDialog::Alert("They Don't Match");,c++,C++,代码出了什么问题?我无法想象这为什么行不通?有任何建议?在C++字符数组中,不能用==运算符进行比较。必须使用StrcMP函数或字符串比较函数。 < P>这是一个非常常见的问题。一旦我在其他问题中找到了一个好的答案,我会将它标记为重复 同时,你不是在比较字符s,而是在比较字符【】s,这是完全不同的。您可能希望使用strcmp、strncmp或std::string类型是更好的解决方案 对代码中发生的事情以及原因有一些合理的解释。您可能想看看这不是i配对两个字符。这是比较两个C样式的字符数组。使用

代码出了什么问题?我无法想象这为什么行不通?有任何建议?在C++字符数组中,

不能用==运算符进行比较。必须使用StrcMP函数或字符串比较函数。

< P>这是一个非常常见的问题。一旦我在其他问题中找到了一个好的答案,我会将它标记为重复

同时,你不是在比较字符s,而是在比较字符【】s,这是完全不同的。您可能希望使用strcmp、strncmp或std::string类型是更好的解决方案


对代码中发生的事情以及原因有一些合理的解释。

您可能想看看这不是
i配对两个字符。这是比较两个C样式的字符数组。使用
std::string
代替与字符串相关的需求。