C++ 中的wcscoll() 函數比較兩個以空字符結尾的字符串。比較基於LC_COLLATE 類別定義的當前語言環境。
wcscoll() 函數在<cwchar> 頭文件中定義。
wcscoll()原型
int wcscoll( const wchar_t* lhs, const wchar_t* rhs );
wcscoll() 函數有兩個參數:lhs
和rhs
.它比較的內容lhs
和rhs
基於當前的語言環境LC_COLLATE 類別。
參數:
lhs
和rhs
:指向要比較的空終止寬字符串的指針。
返回:
wcscoll() 函數返回:
- 如果 lhs 中的第一個不同字符大於 rhs 中的相應字符,則為正值。
- 如果 lhs 中的第一個不同字符小於 rhs 中的相應字符,則為負值。
- 如果 lhs 和 rhs 相等,則為 0。
示例:wcscoll() 函數如何工作?
#include <iostream>
#include <clocale>
#include <cwchar>
using namespace std;
void compare(const wchar_t* p1, const wchar_t* p2)
{
if(wcscoll(p1, p2) < 0)
wcout << p1 << L" precedes " << p2 << '\n';
else if (std::wcscoll(p1, p2) > 0)
wcout << p2 << L" precedes " << p1 << '\n';
else
wcout << p2 << L" equals " << p1 << '\n';
}
int main()
{
wchar_t str1[] = L"årtist";
wchar_t str2[] = L"äpple";
setlocale(LC_ALL, "en_US.utf8");
wcout << L"In the American locale: ";
compare(str1, str2);
setlocale(LC_ALL, "sv_SE.utf8");
wcout << L"In the Swedish locale: ";
compare(str1, str2);
return 0;
}
運行程序時,輸出將是:
In the American locale: äpple precedes årtist In the Swedish locale: årtist precedes äpple
相關用法
- C++ wcscoll()用法及代碼示例
- C++ wcscspn()用法及代碼示例
- C++ wcschr()用法及代碼示例
- C++ wcscat()用法及代碼示例
- C++ wcscpy()用法及代碼示例
- C++ wcscmp()用法及代碼示例
- C++ wcstold()用法及代碼示例
- C++ wcsftime()用法及代碼示例
- C++ wcstod()用法及代碼示例
- C++ wcsncmp()用法及代碼示例
- C++ wcstok()用法及代碼示例
- C++ wcsstr()用法及代碼示例
- C++ wcsrchr()用法及代碼示例
- C++ wcsncpy()用法及代碼示例
- C++ wcslen()用法及代碼示例
- C++ wcsspn()用法及代碼示例
- C++ wcstof()用法及代碼示例
- C++ wcstol()用法及代碼示例
- C++ wcspbrk()用法及代碼示例
- C++ wcsncat()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ wcscoll()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。