#include#include int main() { std::wstring str = L"Hello World!"; std::wcout << str << std::endl; // Output: Hello World! str.clear(); std::wcout << str << std::endl; // Output: return 0; }
#includeIn the above example, `str.clear()` is used inside a loop that iterates through the characters of the string. The loop clears the string and outputs an empty string to the console, one for each character in the original string. Package/Library: Standard C++ Library#include int main() { std::wstring str = L"Hello World!"; std::wcout << str << std::endl; // Output: Hello World! for (int i = 0; i < str.size(); i++) { str.clear(); std::wcout << str << std::endl; } return 0; }