如何检查是否设置了std :: string? [英] How to check if a std::string is set or not?
本文介绍了如何检查是否设置了std :: string?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果使用 char *
,我可以将其初始化为 NULL
,然后通过比较来检查它是否设置.如何为 std :: string
做同样的事情?如何检查字符串是否设置?
If using a char*
, I can initialize it to NULL
and later check if it is set by doing a comparison. How to do the same thing for a std::string
? How to check if the string is set or not?
如果我设置的字符串也为空怎么办?我是否必须使用其他标志来检查是否设置了 std :: string
?
What if the string I set to is also empty? Do I have to use an additional flag to check if the std::string
is set or not?
推荐答案
使用 empty()
:
std::string s;
if (s.empty())
// nothing in s
这篇关于如何检查是否设置了std :: string?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文