#include#include using namespace std; int main() { string str1 = ""; string str2 = "Hello World"; if (str1.isNull()) { cout << "String str1 is null or empty." << endl; } else { cout << "String str1 is not null or empty." << endl; } if (str2.isNull()) { cout << "String str2 is null or empty." << endl; } else { cout << "String str2 is not null or empty." << endl; } return 0; }
String str1 is null or empty. String str2 is not null or empty.
#include#include using namespace std; int main() { QString str1 = ""; QString str2 = "Hello World"; if (str1.isNull()) { cout << "String str1 is null or empty." << endl; } else { cout << "String str1 is not null or empty." << endl; } if (str2.isNull()) { cout << "String str2 is null or empty." << endl; } else { cout << "String str2 is not null or empty." << endl; } return 0; }
String str1 is null or empty. String str2 is not null or empty.In Example 1, we used the C++ standard library's String class. In Example 2, we used the Qt library's QString class.