g++ 错误:“stricmp"未在此范围内声明(但“strcmp"可以)

2022-01-23 00:00:00 g++ c++

我正在尝试编译以下非常非常简单的源代码:

I am trying to compile the following very very simple piece of source code:

#include <cstring>
// #include <string.h>
// using namespace std;

class Helper {
public:
    int cStringsAreEqual(const char *s1, const char *s2) {
        return stricmp(s1, s2);
    }
};

...但我收到以下错误消息:

... but I am getting the following error message:

   g++ error: ‘stricmp’ was not declared in this scope

但是,当我使用 strcmp() 而不是 stricmp() 时,一切都很好!

However when I use strcmp() instead of stricmp() then everything is fine!

这里有什么问题?允许strcmp()的时候不应该允许stricmp()吗?

What can be wrong here? Shouldn't stricmp() be allowed when strcmp() is allowed?

Sureley,这一切都可以在不使用 strcmp/stricmp 的情况下以更好的方式编写.

Sureley, this all could be written in a much better way without using strcmp/stricmp.

但这不是重点.

我正在移植一个软件――它大量使用了对 stricmp() 的调用.如果可能的话,我想避免将每次调用更改为 stricmp 所需的所有努力.

I am porting a piece of software - which makes much use of calls to stricmp(). And if somehow possible I would like to avoid all of the efforts needed to change every call to stricmp.

对此的任何帮助将不胜感激!

Any help on this would be very much appreciated!

顺便说一句:我正在使用带有 g++ v4.4.1 的 Ubuntu karmic OS (v9.10).

BTW: I am using Ubuntu karmic OS (v9.10) with g++ v4.4.1.

顺便说一句:如您所见,我还使用 '#include string.h' 或 'namespace std' 进行了一些试验,但没有任何帮助.

BTW: as you can see I also made some trials with '#include string.h' or with 'namespace std' but nothing helped.

推荐答案

试试strcasecmp().这是它的手册页.符合 4.4BSD 和 POSIX.1-2001.

Try strcasecmp(). Here's the manual page for it. It is conforming to 4.4BSD and POSIX.1-2001.

相关文章