#include#include using namespace std; int main(){ wstring s = L"Hello World!"; cout << "Size of string is " << s.size() << endl; // Output: Size of string is 12 return 0; }
#includeIn this example, we create a wchar_t array containing the text "John Smith". We then use the wcslen function from the cstring library to get the length of the array, and create a wstring object using the array and length as parameters. Finally, we use the size function to get the number of characters in the string and output the result. Package library: Standard Library, cstring library#include using namespace std; int main(){ wchar_t name[] = L"John Smith"; wstring s(name, wcslen(name)); cout << "Size of string is " << s.size() << endl; // Output: Size of string is 10 return 0; }