gpt4 book ai didi

c++ - .NET 的 String.IsNullOrWhiteSpace 在 C++ 中的等效项是什么?

转载 作者:行者123 更新时间:2023-11-28 00:35:19 29 4
gpt4 key购买 nike

我知道这是一个非常容易手动检查的事情,但是在 C++ 中是否有一种开箱即用的推荐方法来检查 std::string 是空的还是只包含空白字符?

如果标准库没有这个,还有其他库吗?

最佳答案

最简单的答案:

bool
isNullOrWhiteSpace( std::string const& str )
{
return std::find_if(
str.begin(),
str.end(),
[]( unsigned char ch ) { return !isspace( ch ); } )
== str.end();
}

但它可能不是很有用;这取决于全局语言环境,并且不会处理一些最常见的编码(如 UTF-8)。

关于c++ - .NET 的 String.IsNullOrWhiteSpace 在 C++ 中的等效项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21169419/

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