【发布时间】:2013-06-07 08:45:19
【问题描述】:
对于 C++ 样式字符串,函数 strcmpi()、strncmp() 和 strncmpi() 的等效项是什么?
请不要建议使用strcmpi(str1.c_str, str2.c_str)之类的东西。
提前感谢您的帮助。
【问题讨论】:
-
看std::string.compare
对于 C++ 样式字符串,函数 strcmpi()、strncmp() 和 strncmpi() 的等效项是什么?
请不要建议使用strcmpi(str1.c_str, str2.c_str)之类的东西。
提前感谢您的帮助。
【问题讨论】:
如果您使用的是 Boost,则可以使用它来进行不区分大小写的比较:
#include <boost/algorithm/string.hpp>
std::string str1 = "hello, world!";
std::string str2 = "hELLO, World!";
if (boost::iequals(str1, str2))
{
// Strings are identical
}
【讨论】: