Visual Studio中stricmp和_stricmp的区别
Difference of stricmp and _stricmp in Visual Studio?
我可能会问一个愚蠢的问题,但我真的找不到谷歌的答案,而且我还是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:nt%snt%snn", 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: String 1 is %s string 2n", tmp );
/* Case insensitive */
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( "t_stricmp: String 1 is %s string 2n", tmp );
}
结果显示它们是相同的:
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
stricmp: String 1 is equal to string 2
_stricmp: String 1 is equal to string 2
我想知道为什么。。。
stricmp
是POSIX函数,而不是标准的C90函数。为了避免名称冲突,Microsoft不赞成使用不一致的名称(stricmp
),并建议改用_stricmp
。功能上没有区别(stricmp
只是_stricmp
的别名。)
对于许多库函数,包括所有<string.h>
函数,带下划线前缀的版本是微软的想法。我记不清具体是什么了。
非下划线版本具有很强的可移植性。必须以某种方式处理使用_stricmp()
、_strcpy()
等的代码—edit、#defined
等;如果代码将由另一个编译器处理。
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- C++ - "!pointer"和"pointer == nullptr"的区别?
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 返回常量对象引用 (getter) 和仅返回字符串有什么区别?
- 返回递归调用和仅递归调用的区别
- Qt:remove() 和 rmdir() 有什么区别
- 这 4 个 lambda 表达式之间有什么区别?
- 结构体 S { int align; } 之间的区别;(struct 关键字后的名称)和 struct { int al
- (double) 和 double() 之间的区别
- 将向量作为类>(值)<向量启动和向量<类>[值]有什么区别
- typedef 枚举和枚举类有什么区别?
- &C::c 和 &(C::c) 有什么区别?
- Visual Studio中stricmp和_stricmp的区别