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++第十九天的更多相关文章

  1. javaSE第十九天

    第十九天    227 1:异常(理解)    227 (1) 定义    227 a)异常的引入    227 (2)异常的体系    228 (3)异常的处理:    229 A:JVM的默认处理 ...

  2. IT第十九天 - 继承、接口、多态、面向对象的编程思想

    IT第十九天 上午 继承 1.一般情况下,子类在继承父类时,会调用父类中的无参构造方法,即默认的构造方法:如果在父类中只写了有参的构造方法,这时如果在子类中继承时,就会出现报错,原因是子类继承父类时无 ...

  3. OCM_第十九天课程:Section9 —》Data Guard _ DATA GUARD 原理/DATA GUARD 应用/DATA GUARD 搭建

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  4. 孤荷凌寒自学python第七十九天开始写Python的第一个爬虫9并使用pydocx模块将结果写入word文档

    孤荷凌寒自学python第七十九天开始写Python的第一个爬虫9 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 到今天终于完成了对docx模块针对 ...

  5. 孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2

    孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2 (完整学习过程屏幕记录视频地址在文末) 今天继续学习beautifulsoup对象的属性与方法等内容. 一.今天进一步 ...

  6. 孤荷凌寒自学python第五十九天尝试使用python来读访问远端MongoDb数据服务

    孤荷凌寒自学python第五十九天尝试使用python来读访问远端MongoDb数据服务 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第五天.今天的感觉是,mongoDB数 ...

  7. 孤荷凌寒自学python第四十九天继续研究跨不同类型数据库的通用数据表操作函数

    孤荷凌寒自学python第四十九天继续研究跨不同类型数据库的通用数据表操作函数 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天继续建构自感觉用起来顺手些的自定义模块和类的代码. 不同类型 ...

  8. 孤荷凌寒自学python第三十九天python 的线程锁Lock

    孤荷凌寒自学python第三十九天python的线程锁Lock (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 当多个线程同时操作一个文件等需要同时操作某一对象的情况发生时,很有可能发生冲突, ...

  9. 孤荷凌寒自学python第二十九天python的datetime.time模块

     孤荷凌寒自学python第二十九天python的datetime.time模块 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) datetime.time模块是专门用来表示纯时间部分的类. ...

  10. 孤荷凌寒自学python第十九天python函数嵌套与将函数作为返回对象及闭包与递归

    孤荷凌寒自学python第十九天python函数嵌套与将函数作为返回对象及闭包与递归 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) Python函数非常的灵活,今天学习了python函数的以 ...

随机推荐

  1. NUC970烧录文件系统

    燒錄U-Boot依照下列步驟將編譯完成的U-Boot燒錄至NAND Flash/SPI Flash/eMMC 中.U-Boot的編譯方法請參考4.3章節.3.11.1 燒錄所需檔案4. u-boot. ...

  2. 微信小程序 this.setData 修改json里面的值

    page({ data:{ s1:{a:"",b:"b"} }, changeData:function(e){ var cData=this.data.s1; ...

  3. PyQt4布局管理——绝对定位方式

    PyQt4中的布局管理器 布局管理器是编程中重要的一部分.所谓布局管理器是指我们在窗口中安排部件位置的方法.布局管理器有两种工作方式:绝对定位方式(absolute positioning)和布局类别 ...

  4. 一个java源文件中是否可以包括多个类(非内部类)?有何限制?

    可以有多个类,但只能有一个public的类,并且public的类名必须与文件名一致.

  5. 在定时任务中慎用pause,否则造成弹窗没关闭,下一次任务不会成功执行

    在定时任务中慎用pause,否则造成弹窗没关闭,下一次任务不会成功执行. 错误提示为:任务计划程序未启动任务“\php测试”,因为相同任务的实例“{07be63e6-af3f-4339-bc30-f1 ...

  6. JS选中清空

    var inputArray = document.getElementsByTagName("input"); var strArray = []; ; i < input ...

  7. (1.1.6)UVA 10978 Let's Play Magic!(直叙式模拟)

    /* * UVA_10978.CPP * * Created on: 2013年10月6日 * Author: Administrator */ #include <iostream> # ...

  8. android框架---->下沉文字Titanic的使用

    Titanic is a simple illusion obtained by applying an animated translation on the TextView TextPaint ...

  9. 对10进制16位长的主键的缩短处理 NULL

    # 对问题表去除旧有主键,新建自增主键:ALTER TABLE `question`CHANGE COLUMN `id` `id16` bigint(20) NULL COMMENT 'id_to_d ...

  10. Go Configure Support hot reloading.

    Go Configure – Josh Betz https://josh.blog/2017/04/go-configure Go Configure APRIL 27, 2017 # DEVELO ...