C++ Primer 练习题
Dzx_星辰
这个作者很懒,什么都没留下…
展开
-
第16章 模板与泛型编程
16.4 template<typename itator, typename type> itator find(itator it, type f) { while (*it != f) it++; return it; } #include <iostream> #include <vector> #include <list> #include "head.h" using namespace std; int main() { vec原创 2020-08-12 17:45:13 · 126 阅读 · 0 评论 -
第14章 重载运算与类型转换
14.36 #include <iostream> #include <string> #include <vector> using namespace std; class ScanfString { public: ScanfString(istream& in = cin) :is(in) {} string operator() () { getline(is, s); return s; } explicit operator原创 2020-08-12 17:40:42 · 96 阅读 · 0 评论 -
第13章 拷贝控制
13.26 class HasPtr { public: HasPtr() = default; HasPtr(const string& s = string()) : ps(new string(s)), i(0) {} HasPtr(const HasPtr& p) : ps(new string(*p.ps)), i(p.i) {} HasPtr& operator=(const HasPtr& rhs){ auto newp = new str原创 2020-08-12 17:39:20 · 150 阅读 · 0 评论 -
第12章 动态内存
12.1.1 #include<iostream> #include<fstream> #include<vector> #include<memory> #include<string> using namespace std; class StrBlob { public: typedef vector<string>::size_type size_type; StrBlob() : data(make_shared&l原创 2020-08-12 17:31:15 · 90 阅读 · 0 评论 -
第11章 关联容器
11.4 #include<iostream> #include<fstream> #include<map> #include<set> #include<string> #include<iterator> #include<algorithm> using namespace std; int main(int argc, char* argv[]) { map<string, size_t> word原创 2020-08-12 17:25:14 · 95 阅读 · 0 评论 -
第10章 泛型算法
10.24 #include<iostream> #include<vector> #include<list> #include<string> #include<iterator> #include<algorithm> #include<functional> using namespace std; using namespace std::placeholders; bool check_size(int n,原创 2020-08-12 17:19:00 · 101 阅读 · 0 评论 -
第9章 顺序容器
练习 9.51: #include <iostream> #include <string> using namespace std; struct date { unsigned long y; unsigned long m; unsigned long d; date(string s) { string::size_type pos; string::size_type pos2; pos = s.find_first_of(" /"); stri原创 2020-08-12 17:13:05 · 109 阅读 · 0 评论