class basic_string

#include "stdafx.h"
#include<string>
using namespace std;

int main(int argc, char* argv[])
{
	printf("Hello World!\n");
	return 0;
}

//程序中此函数的类成员函数
int SearchEquipment(void *pthis, int a2, int a3)
{
	basic_string<int> strdns;  
	return 0;
}
#include <string>
 
template< 
    typename CharT, 
    typename Traits = std::char_traits< CharT >, 
    typename Allocator = std::allocator< CharT >
> class basic_string;

类模板 basic_string 提供了字符序列如何操作和存储的泛型。下面是针对常见字符类型的特化:

typedef basic_string<char>     string;
typedef basic_string<wchar_t>  wstring;
typedef basic_string<char16_t> u16string;    //C++0x 特征
typedef basic_string<char32_t> u32string;    //C++0x 特征
类型成员
类型成员 定义
traits_typeTraits
value_typeTraits::char_type
allocator_typeAllocator
size_typeAllocator::size_type
difference_typeAllocator::difference_type
referenceAllocator::reference
const_referenceAllocator::const_reference
pointerAllocator::pointer
const_pointerAllocator::const_pointer
iterator随机访问迭代器
const_iterator常量随机访问迭代器
reverse_iteratorstd::reverse_iterator<iterator>
const_reverse_iteratorstd::reverse_iterator<const_iterator>
成员函数
(构造函数)根据字符数组或其它字符串创建字符串
操作符字符串的拼接,赋值,I/O 和比较
assign把字符赋给字符串


元素访问
at访问指定字符,带有边界检查
[[operator_atoperator[] ]]访问指定字符
data返回一个指针,指向字符串第一个字符
c_str返回此字符串对应的标准C字符数组,不可修改
迭代器
begin,cbegin返回迭代器,指向字符串开头
end,cend返回迭代器,指向字符串最后一个元素的下一位置
rbegin,crbegin返回一个反向迭代器,指向字符串结尾
rend,crend返回一个反向迭代器,指向字符串开头的前一位置
容量
capacity返回字符串可以容纳的元素个数
empty若字符串中没有字符,返回'真'
max_size返回字符串可以容纳的最大元素个数
reserve设置字符串的最小容量
size返回字符串中项的个数
length返回字符串长度
resize改变字符串大小
操作
clear清空内容
erase从字符串中移除字符
append向字符串中追加字符或字符串
compare比较两个字符串
replace替换字符串中字符
pop_back移除字符串最后一个字符
push_back在字符串末尾追加一个字符
substr返回特定子串
copy把字符串中字符拷贝到数组中
insert向字符串中插入字符
swap将此字符串内容与另一字符串交换
查找
find在字符串中查找字符
find_first_not_of查找非某字符第一次出现
find_first_of查找字符第一次出现
find_last_not_of查找最后一个非某字符
find_last_of查找字符最后一次出现
rfind查找子串最后一次出现
Allocator
get_allocator| /todo
常量
npos一个特殊值,用于指示 "未找到" 或 "所有剩下的字符"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值