gpt4 book ai didi

c++ - C++中不区分大小写的字符串比较

转载 作者:bug小助手 更新时间:2023-10-28 01:31:13 26 4
gpt4 key购买 nike

在不将字符串全部转换为大写或全部小写的情况下,在 C++ 中进行不区分大小写的字符串比较的最佳方法是什么?

请说明这些方法是否支持 Unicode 以及它们的可移植性。

最佳答案

Boost 包含一个方便的算法:

#include <boost/algorithm/string.hpp>
// Or, for fewer header dependencies:
//#include <boost/algorithm/string/predicate.hpp>

std::string str1 = "hello, world!";
std::string str2 = "HELLO, WORLD!";

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

关于c++ - C++中不区分大小写的字符串比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com