strcoll() function in C++

In this guide, you will learn what is strcoll() function is in C++ programming and how to use it with an example.

2. Source Code Example

#include <iostream>
#include <cstring>
#include <clocale>

int main() {
    setlocale(LC_ALL, "en_US.UTF-8");

    char string1[] = "apple";
    char string2[] = "banana";

    int result = strcoll(string1, string2);
    if(result == 0) {
        std::cout << "Both strings are the same according to the current locale." << std::endl;
    } else if(result < 0) {
        std::cout << "String1 comes before string2 according to the current locale." << std::endl;
    } else {
        std::cout << "String1 comes after string2 according to the current locale." << std::endl;
    }

    return 0;
}


Comments