文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 高等教育 > 理学 > C++字符串操作问题
侵权投诉

C++字符串操作问题

C++字符串操作问题

string类的构造函数:

string(const char *s); //用c字符串s初始化

string(intn,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, intpos = 0) const;//把当前串中以pos开始的n个字符拷贝到以s为起始位置的字符数组中,返回实际拷贝的数目

string的特性描述:

int capacity()const; //返回当前容量(即string中不必增加内存即可存放的元素个数) intmax_size()const; //返回string对象中可存放的最大字符串的长度

int size()const; //返回当前字符串的大小

int length()const; //返回当前字符串的长度

bool empty()const; //当前字符串是否为空

void resize(intlen,char c);//把字符串当前大小置为len,并用字符c填充不足的部分

string类的输入输出操作:

string类重载运算符operator>>用于输入,同样重载运算符operator<<用于输出操作。 函数getline(istream&in,string&s);用于从输入流in中读取字符串到s中,以换行符'\n'分开。

string的赋值:

string &operator=(const string &s);//把字符串s赋给当前字符串

string &assign(const char *s);//用c类型字符串s赋值

string &assign(const char *s,int n);//用c字符串s开始的n个字符赋值

string &assign(const string &s);//把字符串s赋给当前字符串

string &assign(intn,char c);//用n个字符c赋值给当前字符串

string &assign(const string &s,intstart,int n);//把字符串s中从start开始的n个字符赋给当前字符串

string &assign(const_iteratorfirst,const_itertor last);//把first和last迭代器之间的部分赋给字符串

第1页

你可能喜欢

  • c++经典代码大全
  • C语言字符串
  • 数据结构算法面试题
  • 概率论数理统计公式
  • KMP算法
  • 嵌入式C语言
  • C函数库
  • JAVA编程题全集及答案

热门文档

相关文档

  • C++字符串操作问题

    C++字符串操作问题_计算机软件及应用_IT/计算机_专业资料。srting类的应用C++ string 类的构造函数: string(const char *s); string(int n,char c); String...

  • C++ 字符串操作整理

    还有必要再重复一下 C++字符串和 C 字符串转换的问 题,许多人会遇到这样的问题,自己做的程序要调用别人的函数、类什么的(比如数据库连 接函数 Connect(char*,...

  • c++字符串操作函数

    (destination, c); printf("%s\n", destination); return 0; } 函数名: ... C++字符串操作 20页 1下载券 C++字符串操作问题 8页 免费2014 Baidu ...

  • C++字符串操作

    C++字符串操作_IT/计算机_专业资料。C++ string类的基本操作今日推荐 ... 『C 基础入门』字符串操... 暂无评价 6页 免费喜欢此文档的还喜欢...

  • c++字符串处理

    c++字符串处理_IT/计算机_专业资料。 C语言并不是一种很方便的语言,它的...我奇怪了很久,终于有一天我忍不住了,决定解决这个问题,我把上面的memcpy用自己...

  • 字符串的操作

    第06章 字符串操作 25页 1下载券 C++字符串操作问题 8页 1下载券...字符串的操作 (1) 字符串采用数组存储,建立两个字符串 String1 和 String2。...

  • C++字符串操作

    C++字符串操作_工学_高等教育_教育专区。字符串操作是一个不小的主题,在标准...{ string s = "abcdefg1111"; const char * chs1 = s.c_str(); ...

  • C++字符串操作报告

    C++字符串操作报告_计算机软件及应用_IT/计算机_...软件 5. 课程设计中遇到的问题及解决方法 1)在...(387) : error C2063: 'kong' : not a ...

  • C++字符串处理

    好在这不是个大问题, 因为我们有 STL 算法: ...的操作,就要做一点小组合: string s("hello, ... C语言中字符串的处理函数... 5页 免费...

  • 字符串操作

    第06章 字符串操作 25页 1下载券 C++字符串操作问题 8页 1下载券 喜欢此...第3章 字符串 1 使用和操作字符串是编程中的常见内容。在C #中,可以使用...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email