map :: find方法是否支持不区分大小写的搜索?
我有一张地图如下
map<string, vector<string> > directory;
Run Code Online (Sandbox Code Playgroud)
并希望下面的搜索忽略大小写.
directory.find(search_string);
Run Code Online (Sandbox Code Playgroud) 我正在尝试编译以下非常简单的源代码:
#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++中人们发现使用String to Lower case/Upper case的最佳方法是什么?
C++不是一种英语编程语言,这个问题很复杂.有一个很好的多语言方法吗?
我目前正在读取带有键/值对的ini文件.即
isValid = true
Run Code Online (Sandbox Code Playgroud)
获取键/值对时,我需要将一个'true'字符串转换为bool.如果不使用boost,最好的方法是什么?
我知道我可以在值("true","false")上进行字符串比较但是我想在没有ini文件中的字符串区分大小写的情况下进行转换.
谢谢
你如何在std :: set中进行不区分大小写的插入或搜索字符串?
例如-
std::set<std::string> s;
s.insert("Hello");
s.insert("HELLO"); //not allowed, string already exists.
Run Code Online (Sandbox Code Playgroud) 我相信以前会被问到但是找不到它.是否有任何内置(即使用std :: wstring的方法或算法)方式对两个wstring对象进行不区分大小写的比较?
我可能会问一个愚蠢的问题,但我真的找不到谷歌的答案加上我仍然是使用MSVS的初学者.
我最近需要使用函数来比较两个字符串.我不明白的是stricmp和_stricmp的区别.它们都可用于比较字符串并返回相同的结果.我去检查一下:
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstricmp: …Run Code Online (Sandbox Code Playgroud) 我必须检查特定字符串是否以另一个字符串开头.字符串使用utf8编码,比较应不区分大小写.
我知道这与C++中的Case不敏感字符串比较非常相似,但我不想使用boost库,我更喜欢可移植解决方案(如果它"几乎'不可能,我更喜欢面向Linux的解决方案).
在C++ 11中使用其regexp库是否可行?或者只使用简单的字符串比较方法?
我知道有一些方法可以做一些忽略比较,包括迭代字符串或一个好的 SO需要另一个库.我需要把它放在其他可能没有安装它的计算机上.有没有办法使用标准库来做到这一点?现在我正在做......
if (foo == "Bar" || foo == "bar")
{
cout << "foo is bar" << endl;
}
else if (foo == "Stack Overflow" || foo == "stack Overflow" || foo == "Stack overflow" || foo == "etc.")
{
cout << "I am too lazy to do the whole thing..." << endl;
}
Run Code Online (Sandbox Code Playgroud)
这可以极大地提高我的代码的可读性和可用性.感谢您阅读这篇文章.