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

前端 未结 8 841
粉色の甜心
粉色の甜心 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:21

    This method is efficient and should work with output strings as well:

    ostringstream report_string;
    
    if (report_string.tellp() == 0) {
        // do something
    }
    
    0 讨论(0)
  • 2020-12-13 09:21

    Use eof() instead.

    Sample Code:

    stringstream report_string;
    if ( !(report_string.eof()) ) 
        cout << "report_string EMPTY! \n";
    
    0 讨论(0)
提交回复
热议问题