第三章对象、类型和值

对象:用来保存一个指定类型值的一些内存单元。

类型:定义一组可能的值与一组运算(对于一个对象)。

值:根据一个类型来解释的内存中的一组比特。

#include <iostream>
using namespace std;
int main()
{
cout << "Please enter your first name and age\n"<< endl; string first_name;
int age; cin >> first_name;
cin >> age;
cout << "Hello,"<< first_name << "(age" << age <<")\n"<< endl; return ;
}

这里我曾犯了个错误。我是这么写的(想当然了),结果g++了一堆错误提示。

cin >> first_name >> endl;
cin >> age >> endl;

 “字符串+”意味着“连接”,也就是说:

当S1 和 S2是字符串时, S1+S2也是字符串,包含来自S1的字符后接来自S2的多个字符。

例如:S1的值为“Hello",S2的值为”World”,那么S1+S2的值为“Hello World”

 #include <iostream>
using namespace std; int main()
{
cout << "Please enter your first ande second names:\n"<< endl; string s1;
string s2; cin >> s1 >> s2; //read two strings string name = s1 +''+ s2; //concatenate strings cout << "Look,"<< name <<'\n'; return ; }

g++报错提示:13: error: empty character constant

string name = s1 +' '+ s2; //单引号中间应有空格

Programming Principles and Practice Using C++ Notes2的更多相关文章

  1. Programming Principles and Practice Using C++ Notes1

    序 0.4 创造性和问题求解 首要目标是帮助你学会用代码表达你的思想2,而不是叫你如何获得这些思想.沿着这样一个思路,给出很多实列,展示如何求解问题. 我们认为程序设计本事是问题求解的一种描述形式: ...

  2. 时间序列 R 读书笔记 04 Forecasting: principles and practice

    本章開始学习<Forecasting: principles and practice> 1 getting started 1.1 事件的可预言性 一个时间能不能被预言主要取决于以下三点 ...

  3. Coursera公开课Functional Programming Principles in Scala习题解答:Week 2

    引言 OK.时间非常快又过去了一周.第一周有五一假期所以感觉时间绰绰有余,这周中间没有假期仅仅能靠晚上加周末的时间来消化,事实上还是有点紧张呢! 后来发现每堂课的视频还有相应的课件(Slide).字幕 ...

  4. Computer Graphics Principles And Practice (James Foley / Andries Van Dam / Morgan McGuire / David Sklar / James D. Foley 著)

    1 Introduction 2 Introduction to 2D Graphics Using WPF 3 An Ancient Renderer Made Modern 4 A 2D Grap ...

  5. C/C++编程语言学习资料尽收眼底 电子书+视频教程

    Visual C++(VC/MFC)学习电子书及开发工具下载请看这里 史无前例的网络最全最强C/C++资料索引: C/C++编程语言学习资料尽收眼底 电子书+视频教程 VC++/MFC(VC6)开发技 ...

  6. C++的学习资源

    本文总结了几个好的C++网站,以及C++方面的经典书籍.所列书籍或标准可以到这里找找电子版. wikipedia关于C++有关条目,注意看后面“参考文献”和“外部链接”: C++ programmin ...

  7. What books does Bjarne Stroustrup suggest to master C++?

    QUESTION : What books does Bjarne Stroustrup suggest to master C++? ANSWER: A Tour of C++ is a quick ...

  8. [译]C++书籍终极推荐

    转载声明: 翻译仅以技术学习和交流为目的,如需转载请务必标明原帖链接. 来源:http://stackoverflow.com/questions/388242/the-definitive-c-bo ...

  9. C++学习指南

    转载于stackoverflow:http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list 感谢Ge ...

随机推荐

  1. GD-GAN: Generative Adversarial Networks for Trajectory Prediction and Group Detection in Crowds

    GD-GAN: Generative Adversarial Networks for Trajectory Prediction and Group Detection in Crowds 2019 ...

  2. c#怎么解决System.UnauthorizedAccessException异常

    https://blog.csdn.net/qq_38061677/article/details/81157116 代码: using System;namespace Project2048{ c ...

  3. linux升级openssl和php_openssl模块

    一.OpenSSL源码升级 2014年4月8日,XP宣布正式停止服务的日子,也是OpenSSL爆出大漏洞的日子. OpenSSL主要是负责在一些敏感的数据提交上面被广泛使用,不乏大家经常访问的一些网站 ...

  4. np.concatenate

  5. MSYS2 更新源

    博客转载自:https://blog.csdn.net/puputaoexin/article/details/81780492 在使用msys2下载文件的时候回出现下载速度奇慢,且经常因为各种原因报 ...

  6. 转 perl DBI 总结

    https://www.cnblogs.com/homezzm/archive/2011/07/22/2113618.html ##查看已经安装的包 #!/usr/bin/perluse strict ...

  7. [LeetCode] 6. ZigZag Converesion 之字型转换字符串

    The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like ...

  8. [LeetCode] 269. Alien Dictionary 外文字典

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  9. 五、Snapman多人协作电子表格之——Python脚本

    Snapman多人协作电子表格是一个即时工作系统. Snapman中嵌入了Python脚本进行数据处理. 一.Snapman集合python语言介绍 将单元格设置为python脚本的方法:用Snapm ...

  10. LeetCode 445. 两数相加 II(Add Two Numbers II)

    445. 两数相加 II 445. Add Two Numbers II 题目描述 给定两个非空链表来代表两个非负整数.数字最高位位于链表开始位置.它们的每个节点只存储单个数字.将这两数相加会返回一个 ...