c++ prime plus 第四章1~4
来源:互联网 发布:余弦匹配算法 编辑:程序博客网 时间:2024/06/07 14:29
今天本该有一节体育课的,但是下雨了,所以就躲到图书馆看看我的c++。主要看的是指针的一些内容。
1.枚举量,定义符号常量。
2.指针,new和delete,指针和数组的关系。
3.数组的地址,是整个数组的地址。如果想打印字符串的地址,需要强制转换。
//c++ 4.8.3实验.cpp
#include <iostream>using namespace std;int main(){ const char * p = "Hello world!"; cout << p << " at " << (int *) p << endl;//输出指向字符串的地址 int sentence2[4] = {12,45,8,5}; int * p2 = sentence2; cout << p2 << endl; cout << &sentence2 << endl; cout << sentence2+1 << endl; cout << &sentence2+1 << endl; return 0;}//char sentence = "Hello world!";//error: invalid conversion from 'const char*' to 'char'//char sentence[15] = "Hello world!";4.暂时忽略了结构体
//answer
#include <iostream>#include <string>#include <cstring>using namespace std;int main(){ //char firstname[10] = "hell wrld"; //cout << "What is your first name? " ; //cout << firstname << endl; 不能读一行 char name[20] ; cout << "What is your name? " ; cin.getline (name, 20); char firstname[20] ; cout << "What is your first name? " ; cin.get(firstname, 20); cin.get();//get 和 getline 的不同使用 //cout << "What is your last name? "; //string lastname ; //getline(cin, lastname); //strcat_s脱胎于strcat,用于两个字符串的链接,strcat不支持string类型 char lastname[20] ; cout << "What is your last name? " ; cin.getline(lastname, 20); cout << "What letter grade do you deserve? "; char grade; cin >> grade; grade++; cout << "What is your age?"; int age; cin >> age; cout << "Who do you love?"; char hername[20]; cin.get(); cin.getline(hername,20); char allname[80] ; strcpy(allname, firstname); strcat(allname, " , "); strcat(allname, lastname); cout << "Name: " << lastname << " , " << firstname << endl; cout << allname << endl; cout << "Grade: " << grade << endl; cout << "Age: " << age << endl; cout << "lover: " << hername << endl; return 0;}这个没怎么用到指针,好气啊。感觉我看了好长时间,最后写题目没用到。。。
阅读全文
0 0
- c++ prime plus 第四章1~4
- c prime plus第八章
- c prime plus 第十二章
- C Prime Plus第十三章
- C++primer plus第四章
- C Primer plus 第四章
- C Primer Plus 第四章
- c prime plus (第十七章 高级数据结构)
- C Prime plus 第六章习题
- c prime plus第十四章练习题
- C Primer Plus 第四章 编程练习 1-7题
- 《C Primer Plus》第四章编程题
- C++primer plus阅读笔记第四章
- C primer plus 第四章总结
- C++primer Plus 第四章练习题
- c prime plus的副作用
- c prime plus的笔记
- C++prime plus第6版第三章要点
- 一篇文章搞定矩阵相关概念及意义--通俗解释汇总
- 程序程序时报 Error installer failed ; 安装程序失败!
- 局域网络配置
- Tensorflow模型持久化与恢复
- DOS常用命令!
- c++ prime plus 第四章1~4
- TextRank, 关键词和句子抽取
- Osg 实例中用到的资源
- Java自定义注解和运行时靠反射获取注解
- C#根据枚举的数值(Value)获取对应的Name值
- Hadoop中YARN和Container的概念详解
- SCI信件回复
- stack的模拟实现
- Invalid <url-pattern> /*.action in filter mapping错误以及(Servlet和Filter的url匹配url-p)