How do I check if a StringStream variable is empty/null?

前端 未结 8 867
粉色の甜心
粉色の甜心 2020-12-13 08:32

Just a quick question here guys. I\'ve been searching to no avail so far.

A bit more info here:

stringstream report_string;

report_string << \         


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 09:03

    An easy check would be to see if the string content of the stream is empty or not:

    #include
    #include
    
    int main(){
    std::stringstream report_string;
    report_string << ""; // an empty strin g
    
    //emptiness check of stringstream
    assert(report_string.str().empty());
    }
    

提交回复
热议问题