C++_3——库(string)


  这一系列文章的目的是在学习了C++基础后,继续补充一些C++基础和进阶的知识点,包括C++11的相关内容。
以C++11标准为基础。

C++网站:http://www.cplusplus.com/reference/

string value transform
	#include <string>
	
	int std::stoi(const string& str, size_t* idx = 0, int base = 10); 
	int std::stol(const string& str, size_t* idx = 0, int base = 10);
	int std::stoul(const string& str, size_t* idx = 0, int base = 10);
	int std::stoll(const string& str, size_t* idx = 0, int base = 10);
	int std::stoull(const string& str, size_t* idx = 0, int base = 10);
	int std::stof(const string& str, size_t* idx = 0);
	int std::stod(const string& str, size_t* idx = 0);
	int std::stold(const string& str, size_t* idx = 0); 
	
	// 以下方法 仅保留6位小数
	string std::to_string (int val);
	string std::to_string (long val);
	string std::to_string (long long val);
	string std::to_string (unsigned val);
	string std::to_string (unsigned long val);
	string std::to_string (unsigned long long val);
	string std::to_string (float val);
	string std::to_string (double val);
	string std::to_string (long double val);
Iterators operate
	// 正向迭代器
	iterator begin() noexcept;
	iterator end() noexcept;
	// 反向迭代器
	iterator begin() noexcept;
	iterator end() noexcept;
	// 常量正向迭代器
	const_iterator cbegin() noexcept;
	const_iterator cend() noexcept;
	// 常量反向迭代器
	const_iterator crbegin() noexcept;
	const_iterator crend() noexcept;
size & resize & empty & clear
	//
	size_t size() const noexcept;
	size_t length() const noexcept;
	
	void resize (size_t n);
	void resize (size_t n, char c);	// 空闲位置用字符 c 补充
	
	void clear() noexcept;
	bool empty() const noexcept;
Element operate
	//返回引用,可作为左值修改
	char& operator[] (size_t pos);
	char& at (size_t pos);
	char& back();
	char& front();
swap & assign & insert & erase & replace
	void push_back (char c);
	void pop_back();			//删除最后一个字符
	void swap (string& str);	//交换
	//以下有较多重载函数
	string& append (const string& str);				//
	string& assign (const string& str);				//替换
	string& insert (size_t pos, const string& str);	//插入
	string& erase (size_t pos = 0, size_t len = npos);
	string& replace (size_t pos, size_t len, const string& str);
copy & find & substr & compare
	const char* c_str() const noexcept;
	const char* data() const noexcept;
	size_t copy (char* s, size_t len, size_t pos = 0) const;
	
	// 一个字符 搜索第一次出现的位置find 和 搜索最后一次出现位置 rfind
	size_t find (const string& str, size_t pos = 0) const noexcept;	//pos 是搜索起始位置
	size_t find (const char* s, size_t pos = 0) const;
	size_t rfind (const string& str, size_t pos = npos) const noexcept;	
	size_t rfind (const char* s, size_t pos = npos) const;
	
	// 字符串任意字符 搜索第一次的位置 和 搜索最后一次出现位置
	size_t find_first_of (const string& str, size_t pos = 0) const noexcept;
	size_t find_first_of (const char* s, size_t pos = 0) const;
	size_t find_last_of (const string& str, size_t pos = npos) const noexcept;
	size_t find_last_of (const char* s, size_t pos = npos) const;
	size_t find_first_not_of (const string& str, size_t pos = 0) const noexcept;
	size_t find_first_not_of (const char* s, size_t pos = 0) const;
	size_t find_last_not_of (const string& str, size_t pos = npos) const noexcept;
	size_t find_last_not_of (const char* s, size_t pos = npos) const;
	
	// 子串
	string substr (size_t pos = 0, size_t len = npos) const;
	
	//比较,重载较多,也可比较其中一部分字符串
	int compare (const string& str) const noexcept;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值