c 字符串
6页1、string类的构造函数:string(const char *s); /用c字符串s初始化string(int n,char c); /用n个字符c初始化此外,string类还支持默认构造函数和复制构造函数,如string s1;string s2=hello;都是正确的写法。当构造的string太长而无法表达时会抛出length_error异常 string类的字符操作:const char &operator(int n)const;const char &at(int n)const;char &operator(int n);char &at(int n);operator和at()均返回当前字符串中第n个字符的位置,但at函数提供范围检查,当越界时会抛出out_of_range异常,下标运算符不提供检查访问。const char *data()const;/返回一个非null终止的c字符数组const char *c_str()const;/返回一个以null终止的c字符串int copy(char *s, int n, int pos = 0) const;/把当前串中以
2、pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目 string的特性描述:int capacity()const; /返回当前容量(即string中不必增加内存即可存放的元素个数)int max_size()const; /返回string对象中可存放的最大字符串的长度int size()const; /返回当前字符串的大小int length()const; /返回当前字符串的长度bool empty()const; /当前字符串是否为空void resize(int len,char c);/把字符串当前大小置为len,并用字符c填充不足的部分 string类的输入输出操作:string类重载运算符operator用于输入,同样重载运算符operator,=,时返回1,时返回-1,=时返回0string的子串:string substr(int pos = 0,int n = npos) const;/返回pos开始的n个字符组成的字符串 string的交换:void swap(string &s2); /交换当前字符串与s2的值 string类的查找函数:
3、 int find(char c, int pos = 0) const;/从pos开始查找字符c在当前字符串的位置int find(const char *s, int pos = 0) const;/从pos开始查找字符串s在当前串中的位置int find(const char *s, int pos, int n) const;/从pos开始查找字符串s中前n个字符在当前串中的位置int find(const string &s, int pos = 0) const;/从pos开始查找字符串s在当前串中的位置/查找成功时返回所在位置,失败返回string:npos的值 int rfind(char c, int pos = npos) const;/从pos开始从后向前查找字符c在当前串中的位置int rfind(const char *s, int pos = npos) const;int rfind(const char *s, int pos, int n = npos) const;int rfind(const string &s,int pos = npos) c
《c 字符串》由会员小**分享,可在线阅读,更多相关《c 字符串》请在金锄头文库上搜索。
2020年高考真题——理科综合(全国卷Ⅲ)+Word版含答案
2021年绝味鸭脖策划书
2021年熟食店创业方案
2021年熟食店开店策划
2021年卤菜店创业计划书
2021年周黑鸭网络营销策划方案
东大21年1月考试《现代设计方法》考核作业
谈我国行政管理效率的现状及其改观对策(论文)
单证员考试-备考辅导-复习资料:无贸易背景信用证案分析.docx
土木工程毕业生答辩自述.docx
建筑学毕业后工作状态真实写照.doc
C#代码规范(湖南大学).doc
xx区食药监局2019年工作总结及2020年工作计划
2019年中医院药物维持治疗门诊工人先锋号先进事迹
2019年度xx乡镇林长制工作总结
2019年性艾科工作计划书
2019年人才服务局全国扶贫日活动开展情况总结
关于组工信息选题的几点思考
摘了穷帽子 有了新模样
2019年某集团公司基层党支部书记培训班心得体会
2024-04-08 33页
2024-04-08 10页
2024-04-08 25页
2024-04-08 12页
2024-04-08 10页
2024-04-08 21页
2024-04-08 40页
2024-04-08 34页
2024-04-08 28页
2024-04-08 28页