相关疑难解决方法(0)

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);
    }
};
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'进行了一些试验,但没有任何帮助.

c++ g++

26
推荐指数
3
解决办法
6万
查看次数

strcasecmp():非标准函数?

前几天我在CodeReview上创建了一个帖子.一个回答我问题的人建议我不要使用strcasecmp()因为"函数是非标准的[并且]这使得[my]代码不可移植." 这就是我使用它的方式:

int playGame()
{

    char scanned[3];
    printf("Do you wish to play tick-tack-toe?\n");
    scanf("%s", scanned);
    if(strcasecmp(scanned,"yes")==0)
        startGame();

    else
    {
        if (strcasecmp(scanned,"no")==0 || strcasecmp(scanned,"nah")==0 || strcasecmp(scanned,"naw")==0)
        {
            printf("That's too bad!/nThis program will now end.");
            return 1;
        }
        printf("Not valid input!/nThis program will now end.");
        return 1;
    }
return 0;
}
Run Code Online (Sandbox Code Playgroud)

有人可以更深入地解释为什么strcasecmp()有这些限制?

c string comparison

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×1

c++ ×1

comparison ×1

g++ ×1

string ×1