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函数的以 ...
随机推荐
- $.post和jquerySubmit返回json数据获取的区别
$.post("/patrol/patrolDataContent!deleteContent.action",{"ids":ids},function(dat ...
- php实现注册审核功能
本章主要实现注册之后审核通过的功能,共这几部分组成: 1. 创建数据库:mydb数据库的user表 注:isok判断是否通过审核,1为通过,0为未通过. 显示效果: 2.首先做注册界面:zhuce ...
- android框架---->下沉文字Titanic的使用
Titanic is a simple illusion obtained by applying an animated translation on the TextView TextPaint ...
- Excel 2010 Alt+; (分号) --- “只选定当前选定区域中的可视单元格”
excel怎样把筛选出来的加上颜色? 1.选中筛选结果数据区域: 2.同时按下Alt+; (分号)键,选中筛选出的数据: 3.鼠标右键,设置单元格格式: 4.在弹出的对话框中,设置字体.背景颜色,即可 ...
- hdu5009 Paint Pearls[指针优化dp]
Paint Pearls Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 代码片段,lucene基本操作(基于lucene4.10.2)
1.最基本的创建索引: @Test public void testIndex(){ try { Directory directory = FSDirectory.open(new File(LUC ...
- 【BZOJ2314】士兵的放置 树形DP
[BZOJ2314]士兵的放置 Description 八中有N个房间和N-1双向通道,任意两个房间均可到达.现在出了一件极BT的事,就是八中开始闹鬼了.老大决定加强安保,现在如果在某个房间中放一个士 ...
- Oracle下select语句
先看scott下自带的emp表 empno:编号 ename:名字 Job:职位 mgr:上级编号 hiredate:入职时间 sal:薪水 comm:奖金 deptno:部门编号 部门表dep ...
- Oracle下Delete语句
Delete语句 基本语法: delete from 表名 where 条件 注意事项: 1,如果不使用where子句,将表中所有数据全部删除 delete from test; 2,如果要删除某列的 ...
- vs 2015
基于应用要求和要使用的语言选择所需工具. Xamarin for Visual Studio:针对所有设备的 C# 中的常用基本代码 Apache Cordova with Visual Studio ...