![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
c++string类库函数中char变量名叫什么
3个回答
展开全部
value_type;
template<class Char_t>
struct std::char_traits { };
template<> struct std::char_traits<char> {
typedef char char_type;
// ...
}; 也有wchar_t的,但是std::char_traits<wchar_t>是typedef wchar_t char_type;
template<class Ch,class Tr = std::char_traits<Ch>, class Alloc=std::allocator<char> >
class std::basic_string {
public:
typedef size_t size_type;
typedef Tr traits_type;
typedef typename Tr::char_type value_type;
// ...
里面的函数,如:
size_type copy(value_type* p, size_type n, size_type pos=0) const;
};
typedef std::basic_string<char> string;
所以string和wstring都只是typedef这个模板的,basic_string不需要知道实际的字符的实际类型,只要对字符类型做个typedef重命名为value_type,一律以value_type来操作就可以了。
template<class Char_t>
struct std::char_traits { };
template<> struct std::char_traits<char> {
typedef char char_type;
// ...
}; 也有wchar_t的,但是std::char_traits<wchar_t>是typedef wchar_t char_type;
template<class Ch,class Tr = std::char_traits<Ch>, class Alloc=std::allocator<char> >
class std::basic_string {
public:
typedef size_t size_type;
typedef Tr traits_type;
typedef typename Tr::char_type value_type;
// ...
里面的函数,如:
size_type copy(value_type* p, size_type n, size_type pos=0) const;
};
typedef std::basic_string<char> string;
所以string和wstring都只是typedef这个模板的,basic_string不需要知道实际的字符的实际类型,只要对字符类型做个typedef重命名为value_type,一律以value_type来操作就可以了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询