g ++错误:'stricmp'未在此范围中声明(但对于'strcmp'正确) [英] g++ error: ‘stricmp’ was not declared in this scope (but OK for 'strcmp')

查看:2304
本文介绍了g ++错误:'stricmp'未在此范围中声明(但对于'strcmp'正确)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译以下非常简单的源代码片段:

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

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

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

  g ++错误:'stricmp'未在此范围内声明


b $ b

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



这里可能出错了什么?当允许使用strcmp()时,不允许使用stricmp()?



Sureley,所有这些都可以用更好的方式编写而不用strcmp / stricmp。 p>

但这不是这里的问题。



我正在移植一个软件 - stricmp()。



任何帮助将非常感谢!

如果有可能,我想避免所有的努力需要改变每次调用stricmp。

BTW:我用g ++ v4.4.1使用Ubuntu karmic操作系统(v9.10)。



看到我也用'#include string.h'或'namespace std'做了一些试验,但没有任何帮助。

解决方案

strcasecmp()。以下是手册页。它符合4.4BSD和POSIX.1-2001。


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

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

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

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

But that's not the point here.

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!

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

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

解决方案

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

这篇关于g ++错误:'stricmp'未在此范围中声明(但对于'strcmp'正确)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆