#include#include using namespace std; int main() { string str1 = "Hello"; string str2 = ""; if (str1.isNotEmpty()) { cout << "String 1 is not empty." << endl; } else { cout << "String 1 is empty." << endl; } if (str2.isNotEmpty()) { cout << "String 2 is not empty." << endl; } else { cout << "String 2 is empty." << endl; } return 0; }
String 1 is not empty. String 2 is empty.
#include#include using namespace std; int main() { string_view str1 = "Goodbye"; string_view str2 = ""; if (str1.isNotEmpty()) { cout << "String 1 is not empty." << endl; } else { cout << "String 1 is empty." << endl; } if (str2.isNotEmpty()) { cout << "String 2 is not empty." << endl; } else { cout << "String 2 is empty." << endl; } return 0; }
String 1 is not empty. String 2 is empty.In both examples, we are using the `isNotEmpty()` function to check if the string objects contain any characters. The first example uses the `std::string` library, while the second example uses the `std::string_view` library. These libraries are part of the C++ Standard Library.