How to check whether a string is empty or not in C++

1 Answer

0 votes
#include <iostream>
 
int main() {
    std::string s1, s2, s3;
     
    s1 = "";
    s2 = "c++";
     
    std::cout << s1.empty() << "\n";
    std::cout << s2.empty() << "\n";
    std::cout << s3.empty();
    
    return 0;
}
 
 
 
/*
run:
 
1
0
1
 
*/

 



answered Dec 9, 2020 by avibootz

Related questions

1 answer 201 views
1 answer 169 views
1 answer 221 views
1 answer 196 views
2 answers 219 views
...