- 博客(9)
- 资源 (1)
- 收藏
- 关注
原创 c++ primer 13.3节练习(定义自己版本的swap函数并排序)
13.31#include #include #include #include #include #include "StrBlob.h"#include "StrBlobPtr.h"using namespace std;class HashPtr{ friend void swap(HashPtr&, HashPtr&);public: HashPtr(const
2017-12-06 15:33:35 508
原创 c++ primer 13.1.4节练习(合成的拷贝构造函数与自定义拷贝函数区别)
13.1.4节练习目的:Numbered类使每个对象都有唯一的标号情况1:使用合成的拷贝构造函数#include #include #include #include using namespace std;class Numbered{public: Numbered(){ mySeq = num++; }//构造函数 int mySeq; //Numbere
2017-12-04 16:27:41 594
原创 c++ primer 13.13练习(构造,拷贝,析构函数何时发生详解)
13.13理解构造函数,拷贝构造函数,析构函数何时发生,最简单的一个办法就是写一个很简单的类,观察在几个情况下是否发生。#include #include #include #include using namespace std;struct Test{ Test(){ cout << "构造函数" << endl; } Test(const Test &){ cou
2017-12-04 15:14:49 379
原创 c++ primer 12.2.2节练习(使用allocate五步走)
12.26#include #include #include using namespace std;int main(){ /**********1.定义allocator的一个allocator对象,要有类型T********/ allocator alloc; int n = 100; /**********2.allocate(n)分配n个为初始化的内存***
2017-12-03 15:57:42 415
原创 C++ primer 8.3.2节练习(有关ostringstream清空的问题)
8.13输入:电话本输出:检测后并格式化后的电话本,输出错误电话号码#include #include #include #include using namespace std;bool Valid(const string& i){ return(i.size() == 9);}string& Format(string& i){ for (auto
2017-12-01 15:33:50 595
原创 c++ primer 8.2.1节练习(读文件 写文件 fstream)
8.4#include #include #include #include using namespace std;int main(){ ifstream input("F:\\test\\input.txt");//打开文档,string中有'\'应用转义双写 vector Test{}; string temp1; if (getline(input, te
2017-12-01 13:25:28 409
原创 c++ primer 8.1.2节练习(关于流的知识)
8.1#include #include using namespace std;istream & Process(istream & i)//对于流对象,不能拷贝和赋值,必须使用引用来传递实参{ int test; while (i >> test||!i.eof()) { if (i.bad()) throw runtime_error("IO流发生不可恢
2017-12-01 13:21:24 608
原创 c++ primer 12.1.4节练习(自定义 shared_ptr的删除器)
12.14#include #include #include #include using namespace std;string destination = "目的";string connection = "连接";string Connect(string *) //获得一个连接{ cout << "获得一个连接" << endl; string temp
2017-12-01 13:17:23 323
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人