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:
- str1: This represents the pointer to the first string to be compare.
- str2: This represents the pointer to the second string to be compare.
Return Value: This method returns:
- Zero: If the str1 and str2 are same.
- Positive value: If the first different character in str1 is greater than the corresponding character in str2.
- Negative value: If the first different character in str1 is less than the corresponding character in str2.
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; } |
Comparing Computer and Science = -1 Comparing Science and Science = 0 Comparing Science and Computer = 1
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
Recommended Posts:
- wcscpy() function in C++ with Examples
- quick_exit() function in C++ with Examples
- btowc() function in C/C++ with Examples
- wcsspn() function in C/C++ with Examples
- wcslen() function in C++ with Examples
- conj() function in C++ with Examples
- norm() function in C++ with Examples
- not1 and not2 function templates in C++ STL with Examples
- ios fail() function in C++ with Examples
- ios bad() function in C++ with Examples
- ios setstate() function in C++ with Examples
- ios good() function in C++ with Examples
- ios eof() function in C++ with Examples
- ios clear() function in C++ with Examples
- ios rdstate() function in C++ with Examples
- ios operator() function in C++ with Examples
- ios operator() function in C++11 with Examples
- ios operator !() function in C++ with Examples
- iomanip resetiosflags() function in C++ with Examples
- iomanip setfill() function in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

