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

g++ error: ‘stricmp’ was not declared in this scope (but OK for #39;strcmp#39;)(g++ 错误:“stricmp未在此范围内声明(但“strcmp可以))
本文介绍了g++ 错误:“stricmp"未在此范围内声明(但“strcmp"可以)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于g++ 错误:“stricmp"未在此范围内声明(但“strcmp"可以)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)