std::wcsncmp
STD::wcsncmp
Defined in header | | |
---|---|---|
int wcsncmp( const wchar_t* lhs, const wchar_t* rhs, std::size_t count | | |
最多比较count
两个以空结尾的宽字符串的宽字符。比较是按字典顺序进行的。
结果的符号是所比较的字符串中第一对宽字符的值之间差异的符号。
如果lhs
或rhs
不是指向以空结尾的字符串的指针。
参数
lhs, rhs | - | pointers to the null-terminated wide strings to compare |
---|---|---|
count | - | maximum number of characters to compare |
返回值
负值lhs
出现在前面rhs
按字典顺序排列。
零中频lhs
和rhs
比较平等。
正值lhs
出现在rhs
按字典顺序排列。
例
二次
#include <iostream>
#include <cwchar>
#include <clocale>
#include <locale>
void demo(const wchar_t* lhs, const wchar_t* rhs, int sz)
{
int rc = std::wcsncmp(lhs, rhs, sz
if(rc == 0)
std::wcout << "First " << sz << " characters of ["
<< lhs << "] equal [" << rhs << "]\n";
else if(rc < 0)
std::wcout << "First " << sz << " characters of ["
<< lhs << "] precede [" << rhs << "]\n";
else if(rc > 0)
std::wcout << "First " << sz << " characters of ["
<< lhs << "] follow [" << rhs << "]\n";
}
int main()
{
const wchar_t str1[] = L"안녕하세요";
const wchar_t str2[] = L"안녕히 가십시오";
std::setlocale(LC_ALL, "en_US.utf8"
std::wcout.imbue(std::locale("en_US.utf8")
demo(str1, str2, 5
demo(str2, str1, 8
demo(str1, str2, 2
}
二次
产出:
二次
First 5 characters of [안녕하세요] precede [안녕히 가십시오]
First 8 characters of [안녕히 가십시오] follow [안녕하세요]
First 2 characters of [안녕하세요] equal [안녕히 가십시오]
二次
另见
strncmp | compares a certain amount of characters of two strings (function) |
---|---|
wcscmp | compares two wide strings (function) |
wmemcmp | compares a certain amount of wide characters from two arrays (function) |
wcscoll | compares two wide strings in accordance to the current locale (function) |
c wcsncmp文档
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。