#include#include int main() { std::wstring str1 = L"Hello"; std::wstring str2 = L""; if (str1.empty()) { std::cout << "str1 is empty\n"; } else { std::cout << "str1 is not empty\n"; } if (str2.empty()) { std::cout << "str2 is empty\n"; } else { std::cout << "str2 is not empty\n"; } return 0; }
str1 is not empty str2 is empty
#include#include int main() { std::wstring str = L""; if (str.empty()) { std::wcout << L"Please enter some text: "; getline(std::wcin, str); } std::wcout << L"The entered text is: " << str << std::endl; return 0; }
Please enter some text: Hello World! The entered text is: Hello World!This example showcases the usage of `empty()` function to prompt the user to input some text if the wstring object is empty. Package library: Standard Library.