如何检查StringStream变量是否为空? [英] How do I check if a StringStream variable is empty/null?
问题描述
这里是一个简单的问题。
这里有更多的信息:
/ p> stringstream report_string;
report_string<< some string here ...;
在我的代码中,有各种条件为report_string变量赋值。
我想检查它是否被分配了一个值。
code> myStream.rdbuf() - > in_avail()可用于获取可从 stringstream
,你可以使用它来检查你的 stringstream
是否为空。我假设你不是真的试图检查值 null
。
例如,如果你想从 stringstream
中提取 int
,然后查看是否有任何剩余字符(即非数字)您可以检查 myStream.rdbuf() - > in_avail()== 0
。
类似于你想做什么?
编辑:我可以使用这个方法看到你刚刚更新你的问题,因为我发布。
Just a quick question here guys. I've been searching to no avail so far.
Thanks!
A bit more info here:
stringstream report_string;
report_string << "some string here...";
In my code itself are various conditions for assigning values to the report_string variable.
I'd like to check whether it was assigned a value or not.
myStream.rdbuf()->in_avail()
can be used to get the count of available characters ready to be read in from a stringstream
, you can use that to check if your stringstream
is "empty." I'm assuming you're not actually trying to check for the value null
.
For example if you want to extract an int
from a stringstream
and then see if there were any left over characters (ie. non-numeric) you could check if myStream.rdbuf()->in_avail() == 0
.
Is that something similar to what you're trying to do? I'm not sure if there's better ways but I've done this in the past and it's worked fine for me.
EDIT: I see you just updated your question as I posted.
这篇关于如何检查StringStream变量是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!