我正在尝试编译以下非常简单的源代码:
#include <cstring>
// #include <string.h>
// using namespace std;
class Helper {
public:
int cStringsAreEqual(const char *s1, const char *s2) {
return stricmp(s1, s2);
}
};
Run Code Online (Sandbox Code Playgroud)
...但我收到以下错误消息:
g++ error: ‘stricmp’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
但是当我使用strcmp()而不是stricmp()时,一切都很好!
这可能有什么不对?当strcmp()被允许时,是否应该允许stricmp()?
Sureley,这一切都可以用更好的方式编写而不使用strcmp/stricmp.
但这不是重点.
我正在移植一个软件 - 它充分利用了对stricmp()的调用.如果可能的话,我想避免所有改变每次调用stricmp所需的努力.
任何有关这方面的帮助将非常感谢!
BTW:我正在使用带有g ++ v4.4.1的Ubuntu karmic OS(v9.10).
顺便说一句:正如你所看到的,我也用'#include string.h'或'namespace std'进行了一些试验,但没有任何帮助.
Mar*_*off 14
stricmp
既不是POSIX也不是ANSI,所以strcmp
如果您的编译器或标准库严格遵守POSIX或ANSI标准库函数(如GCC套件的情况那样),是否允许它并不重要.
Rya*_*sen 11
为它添加一个define来在你要查找的平台上用strcasecmp覆盖stricmp.
#ifdef _IPHONE <- your platform define here
#define stricmp strcasecmp
#define strnicmp strncasecmp
#endif
Run Code Online (Sandbox Code Playgroud)
然后你可以一直使用stricmp.