2.class / string / cctype
来源:互联网 发布:从此山高水长君不必知 编辑:程序博客网 时间:2024/06/05 07:51
class
类(class)类型是一种自定义的类型,每一个类都定义了接口和实现
1. 定义类
class Sales_item{public:private: std::string isbn; unsigned units_sold; double revenue;};//不要忘记这里的;
2.使用struct定义类
Cpp支持使用strcut关键字定义类,总得来说struct定义的类和class定义的类没有什么不同,唯一的不同是,class定义的类的默认访问级别为private,struct定义的类的默认访问级别为public,仅此而已。
strig
string类型支持可变长度的字符串,有标准库管理与存储字符相关的内存,这就是说,我们不必关系数据如何存储,也不必关系平台。
1.定义和初始化
首先使用string必须引用头文件string
。
string s1; //默认构造函数,构建空串string s2(s1);//拷贝构造函数,初始化为s1的一个副本string s3("value");//将s3初始化为字面值"value"的一个副本string s4(n,'c');//构建n个c
2.需要注意:string和“string”不是同一种类型
3.string的读写
string对象对 <<
和>>
运算符进行了重载,所以我们可以通过这两个运算符和iostream对string进行读写操作,当使用cin对string进行读操作时,读取字符直到遇到空白字符为止(空格、制表符、换行),同时也会忽略开头所有的空白符,例如
cin>>s1>>s2;cout#include #include using namespace std;int main(int argc,const char *argv[]){ string s1="string____1"; string s2=""; s2=s1; s2="string____2"; cout
cctype
前面谈到string,我们经常需要对string进行一些操作,例如:判断某个字符是否是数字,是否是空格,是否是字母等等,当然我们可以自己实现函数来判断,不过标准库为我们提供了这些函数,如下这些函数都包含在cctype头文件中
isalnum(c) //如果c是字母和数字,返回trueisalpha(c) //如果c是字母,返回trueisdigit(c) //如果c是数字,返回trueislower(c) //如果c是小写字母,返回trueissuper(c) //如果c是大写字母,返回trueispunct(c) //如果c是标点符号,返回trueisspace(c) //如果c是空白字符,返回trueisgraph(c) //如果c不是空格,返回trueisprint(c) //如果c是可打印字符,返回trueiscntrl(c) //如果c是控制字符,返回trueisxdigit(c) //如果c是十六进制数字,返回truetolower(c) //返回c的小写形式toupper(c) //返回c的大写形式
阅读全文
0 0
- 2.class / string / cctype
- cctype
- cctype
- cctype
- cctype
- <cctype>
- C++中std::string的成员函数 、cctype的函数
- String Class
- String Class
- class string
- cctype <ctype.h> <cctype>
- C++库常用函数一览(<string><cctype><algorithm><cmath><cstdlib><iomanip><numeric>)
- C++库常用函数一览(<string><cctype><algorithm><cmath><cstdlib><iomanip><numeric>)
- C++库常用函数一览 :<string> <cctype> <algorithm> <cmath> <cstdlib> <iomanip> <numeric>
- C++库常用函数一览(<string><cctype><algorithm><cmath><cstdlib><iomanip><numeric>)
- ctype->cctype
- #include <cctype>
- cctype函数
- <<、>>和>>>的区别
- tcp/ip学习笔记--第21章 Timeout and Retransmission
- nit_241_三角形数
- 使用Jsoup爬虫获取统计局全国地区信息
- 威尔逊定理
- 2.class / string / cctype
- 【angular】组件:@Input() @Output() 输入属性和输出属性以及中间人模式的使用 (一)
- moho pro 12中文破解版V12.4下载 | 二维动画制作工具 | moho pro 12.4下载
- zookeeper-Leader选举
- MAN异机异目录恢复
- 剑指offer题目java实现
- Glide和Picasso
- VMware之 桥接网络与NAT 网络模式
- java对称加密与非对称加密