Open In App

wcscmp() function in C++ with Examples

The wcscmp() function is defined in cwchar.h header file. The wcscmp() function is used to compares two null terminating wide string and this comparison is done lexicographically. 

Syntax:

int wcscmp(const wchar_t* str1, const wchar_t* str2);

Parameters: This method takes the following two parameters:

Return Value: This method returns:

Time Complexity: O(n) where n is the size of the smaller string.
Auxiliary Space: O(1)

Below programs illustrate the above function:- 

Example 1:- 




// c++ program to demonstrate
// example of wcscmp() function.
 
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // initialize the str1
    wchar_t str1[] = L"Computer";
 
    // initialize the str2
    wchar_t str2[] = L"Science";
 
    // Compare and print results
    wcout << L"Comparing " << str1 << L" and "
        << str2 << L" = " << wcscmp(str1, str2) << endl;
 
    // Compare and print results
    wcout << L"Comparing " << str2 << L" and "
        << str2 << L" = " << wcscmp(str2, str2) << endl;
 
    // Compare and print results
    wcout << L"Comparing " << str2 << L" and "
        << str1 << L" = " << wcscmp(str2, str1) << endl;
 
    return 0;
}

Output:
Comparing Computer and Science = -1
Comparing Science and Science = 0
Comparing Science and Computer = 1
Article Tags :
C++