C++ strcoll() Function

Last Updated:

C++ strcoll()

The strcoll() function compares two strings depends upon the LC_COLLATE settings.

This function is defined in <cstring> header file.

Example

C++ Compiler
#include <iostream> #include <cstring> #include <clocale> using namespace std; int main() { const char str1[] = "Hallo"; const char str2[] = "HALLO"; // de_DE - German setlocale(LC_COLLATE, "de_DE.UTF-8"); int res = strcoll(str1, str2); if(res == 0) cout << "str1 is equal to str2"; else if(res > 0) cout << "str1 is greater than str2"; else cout << "str1 is less than str2"; return 0; }

Syntax

int strcoll(const char *str1, const char *str2)

Parameter Values

ValueTypeExplanation
str1 Required Specifies the string 1
str2 Required Specifies the string 2

Return Value

ValueExplanation
-1 If str1 is less than str2
0 If str1 is equal to str2
1 If str1 is greater than str2

Share this Page

Meet the Author