【问题标题】:C++ - str(n)cmp(i) () for C++ style strings [duplicate]C++ - 用于 C++ 样式字符串的 str(n)cmp(i) () [重复]
【发布时间】:2013-06-07 08:45:19
【问题描述】:

对于 C++ 样式字符串,函数 strcmpi()strncmp()strncmpi() 的等效项是什么?

请不要建议使用strcmpi(str1.c_str, str2.c_str)之类的东西。

提前感谢您的帮助。

【问题讨论】:

标签: c++ string


【解决方案1】:

如果您使用的是 Boost,则可以使用它来进行不区分大小写的比较:

#include <boost/algorithm/string.hpp>

std::string str1 = "hello, world!";
std::string str2 = "hELLO, World!";

if (boost::iequals(str1, str2))
{
    // Strings are identical
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    • 2021-05-19
    • 2011-01-15
    • 2017-04-16
    • 2011-07-22
    • 1970-01-01
    • 2011-11-05
    相关资源
    最近更新 更多