📄 chartrts.htm
字号:
<html>
<head>
<title>char_traits</title>
<head>
<body bgcolor="#FFFFFF">
<a name="here"></a>
<img src="charban.gif">
<pre>
<font size=5>Class Name</font> char_traits
<font size=5>Header File</font> <string>
<font size=5>Classification</font> Runtime Support
</pre>
<a href="chartrts.htm#crd">Class Relationship Diagram</a><br>
<br>
<a href="chartrts.htm#class-descrip">Class Description</a>
<h1>Member Classes</h1>
<p>
None
</p>
<h1>Methods</h1>
<pre>
<a href="chartrts.htm#assign1">static void assign(char_type& c1, const char_type& c2);</a>
<a href="chartrts.htm#assign2">static char_type* assign(char_type* s, size_t n, char_type a);</a>
<a href="chartrts.htm#compare">static int compare(const char_type* s1, const char_type* s2, size_t n);</a>
<a href="chartrts.htm#copy">static char_type* copy(char_type* s1, const char_type* s2, size_t n);</a>
<a href="chartrts.htm#eq1">static bool eq(const char_type& c1, const char_type& c2);</a>
<a href="chartrts.htm#eq2">static bool eq_int_type(const int_type& c1, const int_type& c2);</a>
<a href="chartrts.htm#find">static const char_type* find(const char_type* s, int n, const char_type& a);</a>
<a href="chartrts.htm#get-state">static state_type get_state(pos_type pos); static int_type eof();</a>
<a href="chartrts.htm#length">static size_t length(const char_type* s);</a>
<a href="chartrts.htm#lt">static bool lt(const char_type& c1, const char_type& c2);</a>
<a href="chartrts.htm#move">static char_type* move(char_type* s1, const char_type* s2, size_t n);</a>
<a href="chartrts.htm#not-eof">static int_type not_eof(const int_type& c);</a>
<a href="chartrts.htm#to-char-type">static char_type to_char_type(const int_type& c);</a>
<a href="chartrts.htm#to-int-type">static int_type to_int_type(const char_type& c);</a>
</pre>
<hr>
<a name="class-descrip"><h3>Class Description</h3></a>
<p>
The char_traits class defines the characters
used in a string, number, time, date etc. Therefore, any class that
manipulates characters is dependent on char_traits class.
For example, when two strings are compared for equality, the characters of
one string are compared with the characters of another string
character-by-character. This string comparison operation calls the
comparison operation of the char_traits class defined for that particular
character type.The char_traits class declares types and functions needed to
manipulate the character type. The functions define comparisons, equality,
assignment, etc., between characters. The actual definition of the
char_traits class is totally dependent on the character type inuse.
Each character type will have its own definition of the char_traits class.
The character traits must be specialized for the specific character type in
use.<br>
<br>
Characters can be narrow or wide. A narrow character is a character
represented by 8 bits. A wide character is a character represented by two
or more bytes. The ASCII character set has 256 8-bit characters. They are
narrow characters. The Unicode charact
er set consists of 65,536 16-bit characters. They are wide characters.
Narrow characters and wide characters are represented as:<br>
<br>
</p>
<pre>
char and wchar_T
</pre>
<hr>
<a name="char-type"><h3>CHAR_T char_type</h3>
<p>
The char_type is of type CHAR_T. It refers to the character container type.
</p>
<hr>
<a name="int-type"><h3>INT_T int_type</h3></a>
<p>
The int_type is of type INT_T. For certain character container type
char_type, container type INT_T shall be a type or class which represents
all of the valid characters converted from a corresponding char_type values.
</p>
<hr>
<a name="pos-type"><h3>POS_T pos_type;</h3></a>
<p>
The pos_type is of type POS_T. For a streambuf or its derived classes
specialized for CHAR_T and TRAIT_T, a type or class POS_T is used to
hold all the information necessary to reposition the specialized
streambuf or its derived classes.
</p>
<a name="state-type"><h3>STATE_T state_type;</h3></a>
<p>
The state_type is of type STATE_T. For a streambuf or its derived classes
whose underlying stream is a multibyte character stream and specialized
for CHAR_T and TRAIT_T, a type or class STATE_T is used represent
the conversion state type or class which is applied to the codecvt<> facet.
</p>
<hr>
<pre>
<a name="assign1">
Method assign()</a>
Access Public
Clasification Modifier
Syntax static void assign(char_type& c1,
const char_type& c2);
Parameters <em>c1</em> is a reference to a <a href="chartrts.htm#char-type">char_type</a> in which c2 is copied
to.
<em>c2</em> is a reference to <a href="chartrts.htm#char-type">char_type</a> which is copied to
c1.
Returns None
</pre>
<h3>Description</h3>
<p>
This assign() method copies <em>c2</em> to <em>c1</em>.
</p>
<hr>
<pre>
<a name="assign2">
Method assign()</a>
Access Public
Classification Modifier
Syntax static char_type* assign(char_type* s, size_t n,
char_type a);
Parameters <em>s</em> points to a sequence of characters in which the
characters are copied.
<em>n</em> is the number of characters.
<em>a</em> is the character to be copied.
Returns This method returns a pointer to a sequence of
char_type characters.
</pre>
<h3>Description</h3>
<p>
The assign() method copies <em>n</em> copies of <em>a</em> into <em>s</em>.
</p>
<hr>
<pre>
<a name="compare">
Method compare()</a>
Access Public
Classification Accessor
Syntax static int compare(const char_type* s1,
const char_type* s2, size_t n);
Parameters <em>s1</em> points to a sequence of characters which is compared
to the characters in the s2 array.
<em>s2</em> points to a sequence of characters which is compared
to the characters in the s1 array.
<em>n</em> is the number of characters in the arrays to
compare.
Returns This method returns 0 if s1[i] == s2[i] where i is
in the range 0 to n.
</pre>
<h3>Description</h3>
<p>
The compare() method for each <a href="chartrts.htm#char-type">char_type</a>
in the range of 0 to n, this function returns 0 if <em>s1</em>[i] == <em>s2</em>[i].
A negative value is returned if <em>s1</em>[i] < <em>s2</em>[i] is
true and in the range 0 to i, <em>s1</em>[j] == <em>s2</em>[j] is
also true. If these conditions are not met then a positive value is returned.
</p>
<hr>
<pre>
<a name="copy">
Method copy()</a>
Access Public
Classification Modifier
Syntax static char_type* copy(char_type* s1,
const char_type* s2,
size_t n);
Parameters <em>s1</em> points to a sequence of characters in which
characters of array s2 are copied.
<em>s2</em> points to a sequence of characters in which the
characters are copied to the array s1.
<em>n</em> is the number of characters.
Returns This method returns a pointer to a sequence of
char_type characters.
</pre>
<h3>Description</h3>
<p>
The copy() method copies <em>n</em> characters from <em>s2</em> to <em>s1</em>
using the assign(s[i],s2[i]).
</p>
<hr>
<pre>
<a name="eq2">
Method eq_int_type()</a>
Access Public
Classification Accessor
Syntax static bool eq_int_type(const int_type& c1,
const int_type& c2);
Parameters <em>c1</em> is a reference to a <a href="chartrts.htm#int-type">int_type</a>
object which is compared to the <a href="chartrts.htm#int-type">int_type</a> of c2.
<em>c2</em> is a reference to a <a href="chartrts.htm#int-type">int_type</a>
object which is compared to the <a href="chartrts.htm#int-type">int_type</a> of c1.
Returns This method returns true if c1 == c2.
</pre>
<h3>Description</h3>
<p>
The eq_int_type() method determines if <em>c1</em> == <em>c2</em>.
The <a href="chartrts.htm#int-type">int_type</a>s are compared for
equivalence.
</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -