Programming Principles and Practice Using C++ Notes2
第三章对象、类型和值
对象:用来保存一个指定类型值的一些内存单元。
类型:定义一组可能的值与一组运算(对于一个对象)。
值:根据一个类型来解释的内存中的一组比特。
#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的更多相关文章
- Programming Principles and Practice Using C++ Notes1
序 0.4 创造性和问题求解 首要目标是帮助你学会用代码表达你的思想2,而不是叫你如何获得这些思想.沿着这样一个思路,给出很多实列,展示如何求解问题. 我们认为程序设计本事是问题求解的一种描述形式: ...
- 时间序列 R 读书笔记 04 Forecasting: principles and practice
本章開始学习<Forecasting: principles and practice> 1 getting started 1.1 事件的可预言性 一个时间能不能被预言主要取决于以下三点 ...
- Coursera公开课Functional Programming Principles in Scala习题解答:Week 2
引言 OK.时间非常快又过去了一周.第一周有五一假期所以感觉时间绰绰有余,这周中间没有假期仅仅能靠晚上加周末的时间来消化,事实上还是有点紧张呢! 后来发现每堂课的视频还有相应的课件(Slide).字幕 ...
- 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 ...
- C/C++编程语言学习资料尽收眼底 电子书+视频教程
Visual C++(VC/MFC)学习电子书及开发工具下载请看这里 史无前例的网络最全最强C/C++资料索引: C/C++编程语言学习资料尽收眼底 电子书+视频教程 VC++/MFC(VC6)开发技 ...
- C++的学习资源
本文总结了几个好的C++网站,以及C++方面的经典书籍.所列书籍或标准可以到这里找找电子版. wikipedia关于C++有关条目,注意看后面“参考文献”和“外部链接”: C++ programmin ...
- 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 ...
- [译]C++书籍终极推荐
转载声明: 翻译仅以技术学习和交流为目的,如需转载请务必标明原帖链接. 来源:http://stackoverflow.com/questions/388242/the-definitive-c-bo ...
- C++学习指南
转载于stackoverflow:http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list 感谢Ge ...
随机推荐
- # advanced packaging
目录 advanced packaging ASM NEXX ASMPT完成收購NEXX 準備就緒迎接先進半導體封裝之高速增長 Intro Bumping 产品供应 晶圆溅镀– Apollo 300 ...
- typescript - 7.模块
我们可以把一些公共的功能单独抽离成一个文件作为一个模块. 模块里面的变量 函数 类等默认是私有的,如果我们要在外部访问模块里面的数据(变量.函数.类), 我们需要通过export暴露模块里面的数据(变 ...
- Mac下epub电子书制作编辑器 : Sigil
官方博客:https://sigil-ebook.com github项目地址:https://github.com/Sigil-Ebook V0.9.10下载:https://github.com/ ...
- 【转载】 LSTM构建步骤以及static_rnn与dynamic_rnn之间的区别
原文地址: https://blog.csdn.net/qq_23981335/article/details/89097757 --------------------- 作者:周卫林 来源:CSD ...
- python初级(302) 3 easygui简单使用二
一.复习 1.easygui 信息提示对话框 2.easygui 是否对话框 二.easygui其它组件 1.选择对话框:choicebox(msg, title, choices) import e ...
- PAT 甲级 1079 Total Sales of Supply Chain (25 分)(简单,不建树,bfs即可)
1079 Total Sales of Supply Chain (25 分) A supply chain is a network of retailers(零售商), distributor ...
- [LeetCode] 875. Koko Eating Bananas 可可吃香蕉
Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The g ...
- 错误:net::ERR_BLOCKED_BY_CLIENT
提示net::ERR_BLOCKED_BY_CLIENT错误 解决办法: 当我们查看浏览器第三方插件的时候,就会看到插件中存在“广告过滤插件”,其实,报错的原因就是第三方广告过滤插件在捣鬼, 当你关闭 ...
- (CSDN迁移)js中的判空
<c:if test="${something.something == NaN}">style="display: none;"</c:if ...
- Java的集合类之 List 接口用法
集合其实在本质上面就是数据结构,它封装了一些底层的数据结构等操作进行操作. 集合的长度是可变的,用来存放对象的引用.常见的集合类有List集合.Set集合.Map集合. 1. List接口 List是 ...