c++第十九天
p109~p110:
C风格字符串
特点:
1、不方便,不安全,尽量不使用。
2、必须以 '\0'结束。(只有这样才能使用C风格字符串函数)
3、一般利用指针操作这些字符。
4、可以用字符串字面值来初始化字符数组。
const char ca1[] = "A C-style character string"; // ca1其实是指向数组首元素的指针。
练习 3.37
这道题输出有点奇怪。。。
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
const char ca[] = {'h', 'e', 'l', 'l', 'o'};
const char *cp = ca;
while (*cp) {
cout << *cp << endl;
++cp;
}
return ;
}
输出结果:
D:\labs>a
h
e
l
l
o
a
练习 3.38
搬运。
Pointer addition is forbidden in C++, you can only subtract two pointers. The reason for this is that subtracting two pointers gives a logically explainable result - the offset in memory between two pointers. Similarly, you can subtract or add an integral number to/from a pointer, which means "move the pointer up or down". Adding a pointer to a pointer is something which is hard to explain. What would the resulting pointner represent? If by any chance you explicitly need a pointer to a place in memory whose address is the sum of some other two addresses, you can cast the two pointers to int, add ints, and cast back to a pointer. Remember though, that this solution needs huge care about the pointer arithmetic and is something you really should never do.
练习 3.39
1
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<cstring>
int main()
{
const char ca1[] = "string-A";
const char ca2[] = "string-B";
if (strcmp(ca1 , ca2) > ) {
cout << "string-A big" << endl;
} else {
cout << "string-B big" << endl;
}
return ;
}
2
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<string>
using std::string;
int main()
{
string s1 = "string-A";
string s2 = "string-B";
cout << "Big one is: ";
if (s1 > s2) {
cout << s1 << endl;
} else {
cout << s2 << endl;
}
return ;
}
练习 3.40
#include<cstring>
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char s1[] = "stringA";
char s2[] = "stringB";
strcat(s1 , s2);
char s[];
strcpy(s , s1);
cout << s << endl;
return ;
}
c++第十九天的更多相关文章
- javaSE第十九天
第十九天 227 1:异常(理解) 227 (1) 定义 227 a)异常的引入 227 (2)异常的体系 228 (3)异常的处理: 229 A:JVM的默认处理 ...
- IT第十九天 - 继承、接口、多态、面向对象的编程思想
IT第十九天 上午 继承 1.一般情况下,子类在继承父类时,会调用父类中的无参构造方法,即默认的构造方法:如果在父类中只写了有参的构造方法,这时如果在子类中继承时,就会出现报错,原因是子类继承父类时无 ...
- OCM_第十九天课程:Section9 —》Data Guard _ DATA GUARD 原理/DATA GUARD 应用/DATA GUARD 搭建
注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...
- 孤荷凌寒自学python第七十九天开始写Python的第一个爬虫9并使用pydocx模块将结果写入word文档
孤荷凌寒自学python第七十九天开始写Python的第一个爬虫9 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 到今天终于完成了对docx模块针对 ...
- 孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2
孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2 (完整学习过程屏幕记录视频地址在文末) 今天继续学习beautifulsoup对象的属性与方法等内容. 一.今天进一步 ...
- 孤荷凌寒自学python第五十九天尝试使用python来读访问远端MongoDb数据服务
孤荷凌寒自学python第五十九天尝试使用python来读访问远端MongoDb数据服务 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第五天.今天的感觉是,mongoDB数 ...
- 孤荷凌寒自学python第四十九天继续研究跨不同类型数据库的通用数据表操作函数
孤荷凌寒自学python第四十九天继续研究跨不同类型数据库的通用数据表操作函数 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天继续建构自感觉用起来顺手些的自定义模块和类的代码. 不同类型 ...
- 孤荷凌寒自学python第三十九天python 的线程锁Lock
孤荷凌寒自学python第三十九天python的线程锁Lock (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 当多个线程同时操作一个文件等需要同时操作某一对象的情况发生时,很有可能发生冲突, ...
- 孤荷凌寒自学python第二十九天python的datetime.time模块
孤荷凌寒自学python第二十九天python的datetime.time模块 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) datetime.time模块是专门用来表示纯时间部分的类. ...
- 孤荷凌寒自学python第十九天python函数嵌套与将函数作为返回对象及闭包与递归
孤荷凌寒自学python第十九天python函数嵌套与将函数作为返回对象及闭包与递归 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Python函数非常的灵活,今天学习了python函数的以 ...
随机推荐
- cocos2d-x游戏引擎核心之十一——并发编程(消息通知中心)
[续] cocos2d-x游戏引擎核心之八——多线程 这里介绍cocos2d-x的一种消息/数据传递方式,内置的观察者模式,也称消息通知中心,CCNotificationCenter. 虽然引擎没有为 ...
- linux mysql添加用户,删除用户,以及用户权限
一些主要的命令: 登录: mysql -u username -p 显示全部的数据库: show databases; 使用某一个数据库: use databasename; 显示一个数据库的全部表: ...
- win8.1简单快速安装phpnow的方法
工具/原料 phpnow 1.5.6 管理员身份登陆系统 方法/步骤 下载phpnow 这是必须的,大家可以自行百度下载,然后我们将phpnow放到一个文件夹,可以是根目录,也可以不是,但一定要知 ...
- 启动Solr时报 _version_ field must exist in schema 错误的解决方法
Solr启动时报 org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Unable to use up ...
- 电力项目十八--DOM对象的ajax
Ajax操作的核心对象:xmlreq = new XMLHttpRequest(); 第一步:在dictionaryIndex.jsp中添加: <script type="text/j ...
- Scala 泛型类型和方法
abstract class Stack[A] { def push(x: A): Stack[A] = new NonEmptyStack[A](x, this) def isEmpty: Bool ...
- 转悠望南山 Python闲谈(二)聊聊最小二乘法以及leastsq函数
1 最小二乘法概述 自从开始做毕设以来,发现自己无时无刻不在接触最小二乘法.从求解线性透视图中的消失点,m元n次函数的拟合,包括后来学到的神经网络,其思想归根结底全都是最小二乘法. 1-1 “多线 ...
- java 中关于System.out.println()的问题
Java 的输出知识 1.System.out.println()不能直接写在类中,例如: 因为在 Class A{ //成员变量 //构造方法 //普通方法 //内部类 } 如果硬是想使用Syste ...
- SpringBoot项目属性配置
如果使用IDEA创建Springboot项目,默认会在resource目录下创建application.properties文件,在SpringBoot项目中,也可以使用yml类型的配置文件代替pro ...
- float和double
Java中,使用Float.floatToRawIntBits()函数获得一个单精度浮点数的IEEE 754 表示,例如: float fNumber = -5; //获得一个单精度浮点数的IEEE ...