std::strxfrm
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cstring> 中定义
|
||
std::size_t strxfrm( const char* dest, const char* src, std::size_t count ); |
||
。为实现定义的形式,比较两种转化的字符串
src
给出了相同的结果,在当前的C语言环境比较原始的字符串std::strcmp变换null结尾的字节串所指向的std::strcoll.原文:
Transforms the null-terminated byte string pointed to by
src
into the implementation-defined form such that comparing two transformed strings with std::strcmp gives the same result as comparing the original strings with std::strcoll, in the current C locale.。
count
的第一个字符的转换后的字符串被写入到目的地,包括终止空字符,返回的全面转化的字符串的长度,不包括终止空字符.原文:
The first
count
characters of the transformed string are written to destination, including the terminating null character, and the length of the full transformed string is returned, excluding the terminating null character.。
count
是0,然后dest
是一个空指针.原文:
If
count
is 0, then dest
is allowed to be a null pointer.目录 |
[编辑] 。注释。
。正确的缓冲区,可以接收整个转化的字符串的长度是1+std::strxfrm(NULL, src, 0)。
原文:
The correct length of the buffer that can receive the entire transformed string is 1+std::strxfrm(NULL, src, 0)
[编辑] 。参数。
dest | - | 。指针数组,其中变换后的字符串将被写入的第一个元素。
原文: pointer to the first element of the array where the transformed string will be written |
src | - | 。改造null结尾的字节串的第一个字符的指针。
原文: pointer to the first character of a null-terminated byte string to transform |
count | - | 。要写入的字符的最大数量。
原文: maximum number of characters to be written |
===。 返回值。===
。转换后的字符串的长度,不包括终止空字符.
原文:
The length of the transformed string, not including the terminating null-character.
[编辑] 。为例。
#include <iostream> #include <iomanip> #include <cstring> int main() { std::setlocale(LC_COLLATE, "cs_CZ.iso88592"); std::string in1 = "hrnec"; std::string out1(1+std::strxfrm(nullptr, in1.c_str(), 0), ' '); std::string in2 = "chrt"; std::string out2(1+std::strxfrm(nullptr, in2.c_str(), 0), ' '); std::strxfrm(&out1[0], in1.c_str(), out1.size()); std::strxfrm(&out2[0], in2.c_str(), out2.size()); std::cout << "In the Czech locale: "; if(out1 < out2) std::cout << in1 << " before " << in2 << '\n'; else std::cout << in2 << " before " << in1 << '\n'; std::cout << "In lexicographical comparison: "; if(in1 < in2) std::cout << in1 << " before " << in2 << '\n'; else std::cout << in2 << " before " << in1 << '\n'; }
输出:
In the Czech locale: hrnec before chrt In lexicographical comparison: chrt before hrnec
[编辑] 。另请参阅。
变换宽字符串,wcscmp会产生相同的结果wcscoll的 原文: transform a wide string so that wcscmp would produce the same result as wcscoll (函数) | |
[虚]</div></div>
|
转换的字符串排序规则,以便通过比较可以被替换 原文: transforms a string so that collation can be replaced by comparison (虚拟保护成员函数of std::collate )
|
按照目前的语言环境比较两个字符串 原文: compares two strings in accordance to the current locale (函数) | |
C documentation for strxfrm
|