名前空間
変種
操作

std::char_traits

提供: cppreference.com
< cpp‎ | string

 
 
ストリングスライブラリ
NULLで終わる文字列
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイト文字列
文字列をマルチバイト
ワイド文字列
クラス
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string
char_traits
 
std::char_traits
メンバ関数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
char_traits::assign
char_traits::cmp
char_traits::move
char_traits::copy
char_traits::compare
char_traits::length
char_traits::find
char_traits::to_char_type
char_traits::to_int_type
char_traits::eq_int_type
char_traits::eof
char_traits::not_eof
 
Defined in header <string>
template<

    class CharT

> class char_traits;
char_traitsクラスには、文字や文字列だけでなく、与えられた文字タイプのためのすべての一般的な操作を操作するために使用される種類として文字型のストリームと文字列操作のプロパティを定義しています.
Original:
The char_traits class defines the stream and string operation properties of a character type, such as the types used for manipulating the characters and character strings, as well as all the common operations for the given character type.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


クラステンプレートchar_traits定義され、明示的なインスタンス生成のための基礎として機能しています。それはTraitsコンセプトのすべての要件を満たして.
Original:
There is class template char_traits defined, which serves as a basis for explicit instantiations. It fulfills all requirements of Traits concept.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
また、いくつかの専門分野は、以下のメンバーを指定する必要があり、最も一般的なキャラクタ·タイプのために定義されています
Original:
Also, several specializations are defined for most common character types which which has to specify the following members:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Instantiation char_type int_type off_type pos_type state_type
char_traits<char> char int streamoff streampos mbstate_t
char_traits<wchar_t> wchar_t wint_t wstreamoff wstreampos mbstate_t
char_traits<char16_t> (C++11) char16_t int_least16_t streamoff u16streampos mbstate_t
char_traits<char32_t> (C++11) char32_t int_least32_t streamoff u32streampos mbstate_t

目次

[編集] メンバータイプ

タイプ
Original:
Type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
char_type CharT
int_type
char_typeのすべての値を保持できる整数型プラスEOF
Original:
an integer type that can hold all values of char_type plus EOF
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
off_type
実装定義
Original:
implementation-defined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pos_type
実装定義
Original:
implementation-defined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
state_type
実装定義
Original:
implementation-defined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] メンバ関数

[静的]
文字を割り当てます
Original:
assigns a character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
二つの文字を比較します
Original:
compares two characters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
別の上に1つの文字列を移動します
Original:
moves one character sequence onto another
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
文字列をコピーします
Original:
copies a character sequence
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
辞書的に2つの文字シーケンスを比較しています
Original:
lexicographically compares two character sequences
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
文字列の長さを返します
Original:
returns the length of a character sequence
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
finds a character in a character sequence
(公共の静的メンバ関数) [edit]
同等int_typechar_typeに変換します
Original:
converts int_type to equivalent char_type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
同等char_typeint_typeに変換します
Original:
converts char_type to equivalent int_type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
2int_type値を比較します
Original:
compares two int_type values
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
' EOFの値を返します
Original:
returns an eof value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]
[静的]
文字がEOF'値であるかどうかをチェックします
Original:
checks whether a character is eof value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(公共の静的メンバ関数) [edit]

[編集]

ユーザー定義文字の特徴はcase-insensitive comparisonを提供するために使用することができる
Original:
User-defined character traits may be used to provide case-insensitive comparison
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <string>
#include <iostream>
#include <cctype>
 
struct ci_char_traits : public std::char_traits<char> {
    static bool eq(char c1, char c2) {
         return std::toupper(c1) == std::toupper(c2);
     }
    static bool ne(char c1, char c2) {
         return std::toupper(c1) != std::toupper(c2);
     }
    static bool lt(char c1, char c2) {
         return std::toupper(c1) <  std::toupper(c2);
    }
    static int compare(const char* s1, const char* s2, size_t n) {
        while( n-- != 0 ) {
            if( std::toupper(*s1) < std::toupper(*s2) ) return -1;
            if( std::toupper(*s1) > std::toupper(*s2) ) return 1;
            ++s1; ++s2;
        }
        return 0;
    }
    static const char* find(const char* s, int n, char a) {
        while( n-- > 0 && std::toupper(*s) != std::toupper(a) ) {
            ++s;
        }
        return s;
    }
};
 
typedef std::basic_string<char, ci_char_traits> ci_string;
 
std::ostream& operator<<(std::ostream& os, const ci_string& str) {
    return os.write(str.data(), str.size());
}
 
int main()
{
    ci_string s1 = "Hello";
    ci_string s2 = "heLLo";
    if(s1 == s2)
        std::cout << s1 << " and " << s2 << " are equal\n";
}

Output:

Hello and heLLo are equal

[編集] も参照してください

店舗や文字の並びを操作します
Original:
stores and manipulates sequences of characters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(クラステンプレート) [edit]