// An example C++ program to demonstrate use of wchar_t
#include <iostream>
using namespace std;
int main()
{
wchar_t w = L'A';
cout << "Wide character value:: " << w << endl ;
cout << "Size of the wide char is:: " << sizeof(w);
return 0;
}
// An example C++ program to demonstrate use
// of wchar_t in array
#include <iostream>
using namespace std;
int main()
{
// char type array string
char caname[] = "geeksforgeeks" ;
cout << caname << endl ;
// wide-char type array string
wchar_t waname[] = L"geeksforgeeks" ;
wcout << waname << endl;
return 0;
}
// An example C++ program to demonstrate use
// of wcslen()
#include <iostream>
#include<cwchar>
using namespace std;
int main()
{
// wide-char type array string
wchar_t waname[] = L"geeksforgeeks" ;
wcout << L"The length of '" << waname
<< L"' is " << wcslen(waname) << endl;
return 0;
}
// An example C++ program to demonstrate use
// of wcscpy()
#include <iostream>
#include<cwchar>
using namespace std;
int main()
{
wchar_t waname[] = L"geeksforgeeks" ;
wchar_t wacopy[14];
wcscpy(wacopy, waname);
wcout << L"Original = " << waname
<< L"\nCopy = " << wacopy << endl;
return 0;
}
// An example C++ program to demonstrate use
// of wcscat()
#include <iostream>
#include<cwchar>
using namespace std;
int main()
{
wchar_t string1[] = L"geeksforgeeks" ;
wchar_t string2[] = L" is for Geeks" ;
wcscat(string1, string2);
wcout << L"Concatenated wide string is = "
<< string1 << endl;
return 0;
}
// An example C++ program to demonstrate use
// of wcscmp()
#include <iostream>
#include<cwchar>
using namespace std;
int main()
{
wchar_t string1[] = L"geeksforgeeks" ;
wchar_t string2[] = L"GEEKS" ;
wcout << L"Comparison1 = "
<< wcscmp(string1, string2) << endl;
wcout << L"Comparison2 = "
<< wcscmp(string1, string1) << endl;
wcout << L"Comparison3 = "
<< wcscmp(string2, string1) << endl;
return 0;
}
// An example C++ program to demonstrate use
// of wcstok()
#include <iostream>
#include<cwchar>
using namespace std;
int main()
{
wchar_t string[] = L"geeksforgeeks,is,for,GEEKS" ;
wchar_t* internal_state;
wchar_t delim[] = L"," ;
wchar_t* token = wcstok(string, delim, &internal_state);
while (token)
{
wcout << token << endl;
token = wcstok(NULL, delim, &internal_state);
}
return 0;
}
// An example C++ program to demonstrate use
// of wcsncpy()
#include <iostream>
#include<cwchar>
using namespace std;
int main()
{
wchar_t string1[] = L"Geeks For Geeks";
wchar_t string2[20];
wchar_t string3[20];
wcsncpy(string2, string1, 20);
// partial copy
wcsncpy(string3, string2, 5);
string3[5] = L'\0'; // null character manually added
wcout << string1 << endl << string2
<< endl << string3 ;
return 0;
}
// An example C++ program to demonstrate use
// of wcsstr()
#include <iostream>
#include<cwchar>
using namespace std;
int main()
{
wchar_t string1[] = L"Geeks Are Geeks";
wchar_t* string2 = wcsstr(string1, L"Are");
wcsncpy(string2, L"For", 3);
wcout << string1 << endl;
return 0;
}