学习Accelerated C++1

第0章
0-2题目
输出指定的话
编程如下
#include
using namespace std;

int main()
{
cout << “This (”)is a quote,and this (\)is abacklash" << endl;
system (“pause”);
return 0;
}

值得注意的是括号里面的“和\的输出
都应用“和\,前面加\,原因在6页上,\“是吧这个符号当做字符串的一部分而不是把它当做字符串的结束,\若字符串中包括一个\,那么就可以吧接下来的字符当做普通字符来处理。

0-4题目
我编写的程序
#include
using namespace std;

int main()
{
cout << “Hello,world!” <<endl;
cout << “This (”)is a quote,and this (\)is a backlash" << endl;
cout << “a small C++ program”<< endl;
cout << “#include " << endl;
cout << “using namespace std;” << endl;
cout << “int main()” << endl;
cout << “{” << endl;
cout << " cout << “Hello, world!” <<endl;” << endl;
cout << " return 0;" << endl;
cout << “}” << endl;
system (“pause”);
return 0;
}
而网上下载下来的程序比自己的简单很多
运用了\n换行符和\t水平制表符
\t水平制表就是调到下个Tab位置 就相当于自己空格

第一章
很多会忘记的小知识点和概念
1.重载
3+4和字符串之间的+的意义不同
运算符对于不同类型的操作数来说具有不同的含义
2.常量 const
在定义常量的时候要赋初值,要不然后面么机会赋值了

string name;
const string m=name;
这样并不代表name也是常量
3.<< +是左结合的
cout<<s<<t相当于(cout<<s)<<t
4.字符直接量 字符串直接量
字符直接量用‘’来括起来 字符串直接量用“”括起来
哪里会用到字符直接量呢
比如
string name=doris;
string first(name.size(),‘ ’);//这里用到了字符直接量
5.给字符定义的方式
string name=”doris“;
string name(first.size()。‘ ’;
string name;.
.
课后题都蛮简单的,上机运行一下就可以

猜你喜欢

转载自blog.csdn.net/Beat_Tao_blow/article/details/88080398
今日推荐