【发布时间】:2009-11-23 17:41:38
【问题描述】:
我正在尝试编译以下非常非常简单的源代码:
#include <cstring>
// #include <string.h>
// using namespace std;
class Helper {
public:
int cStringsAreEqual(const char *s1, const char *s2) {
return stricmp(s1, s2);
}
};
...但我收到以下错误消息:
g++ error: ‘stricmp’ was not declared in this scope
但是,当我使用 strcmp() 而不是 stricmp() 时,一切都很好!
这里有什么问题?允许strcmp()的时候不应该允许stricmp()吗?
Sureley,这一切都可以在不使用 strcmp/stricmp 的情况下以更好的方式编写。
但这不是重点。
我正在移植一个软件——它大量使用了对 stricmp() 的调用。如果可能的话,我想避免将每次调用更改为 stricmp 所需的所有努力。
对此的任何帮助将不胜感激!
顺便说一句:我正在使用带有 g++ v4.4.1 的 Ubuntu karmic OS (v9.10)。
顺便说一句:如您所见,我还使用 '#include string.h' 或 'namespace std' 进行了一些试验,但没有任何帮助。
【问题讨论】:
-
考虑到 stricmp 和 strcmp 不一样(后者区分大小写),您可能需要在更改它们之前犹豫一下。
-
我知道他们不一样。这就是为什么我想使用 stricmp 而不是 strcmp
-
还要注意
<string.h>和<cstring>不完全是一些。这不是您的问题的原因,但您需要编写std::strcmp(或std::strcoll)而不是假设名称已导入全局命名空间。