Fork me on GitHub
上一页 1 ··· 84 85 86 87 88 89 90 91 92 ··· 119 下一页
摘要: 建立一个通用类,类中成员数据类型可以不再指定,用一个虚拟的类型来代表。 基本语法: #include<iostream> using namespace std; template<class NameType,class AgeType> class Person { public: NameTy 阅读全文
posted @ 2019-12-27 11:24 西西嘛呦 阅读(298) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; class Person { public: string name; int age; Person(string name,int age) { this->name = name; this->age = age; 阅读全文
posted @ 2019-12-27 11:18 西西嘛呦 阅读(269) 评论(0) 推荐(0)
摘要: 1.如果模板函数和普通函数都可以实现,则优先调用普通函数。 2.可以通过空模板参数列表来强制调用模板函数; 3.函数模板也可以重载; 4.如果函数模板可以产生更好的匹配,优先调用函数模板; #include<iostream> using namespace std; int myAdd(int a 阅读全文
posted @ 2019-12-27 11:04 西西嘛呦 阅读(3139) 评论(0) 推荐(0)
摘要: 1.普通函数调用时可以发生自动类型转换(隐式类型转换); 2.函数模板调用时,如果利用类型自动推导,不会发生隐式类型转换; 3.如果利用显示指定类的方式,可以发生隐式类型转换; #include<iostream> using namespace std; int myAdd(int a, int 阅读全文
posted @ 2019-12-27 10:45 西西嘛呦 阅读(285) 评论(0) 推荐(0)
摘要: 1.利用函数模板封装一个排序的函数,可以对不同的数据类型数组进行排序。 2.利用的排序算法是选择排序。 #include<iostream> #include<fstream> #include<string> using namespace std; template<class T> void 阅读全文
posted @ 2019-12-26 19:50 西西嘛呦 阅读(379) 评论(0) 推荐(0)
摘要: 模板就是建立通用的模具,大大提高复用性。 c++的另一种编程思想是泛型编程,主要利用的就是模板。 c++提供两种模板机制:函数模板和类模板。 声明:template<class T>//typename可以替换成class 函数模板 函数模板的作用:建立一个通用函数,其函数返回值类型和形参类型可以不 阅读全文
posted @ 2019-12-26 17:34 西西嘛呦 阅读(662) 评论(0) 推荐(1)
摘要: #include<iostream> #include<fstream> #include<string> using namespace std; class Person { public: char name[64]; int age; }; void test() { ifstream if 阅读全文
posted @ 2019-12-26 17:04 西西嘛呦 阅读(282) 评论(0) 推荐(0)
摘要: #include<iostream> #include<fstream> #include<string> using namespace std; class Person { public: char name[64]; int age; }; void test() { ofstream of 阅读全文
posted @ 2019-12-26 16:59 西西嘛呦 阅读(193) 评论(0) 推荐(0)
摘要: #include<iostream> #include<fstream> #include<string> using namespace std; void test() { ifstream ifs; //如若不指定路径,则在该项目同级下生成 ifs.open("test.txt", ios:: 阅读全文
posted @ 2019-12-26 16:52 西西嘛呦 阅读(447) 评论(0) 推荐(0)
摘要: c++对文件进行操作需要使用头文件<fstream> 文本文件:文件以文本的ASCII码形式存储在计算机中; 二进制文件:文件以文件的二进制存储在计算机中,用户一般不能直接读取它们 操作文件的三大类: ofstream:写 ifstream:读 fstream:读写 写文本文件步骤:包含头文件:#i 阅读全文
posted @ 2019-12-26 16:29 西西嘛呦 阅读(912) 评论(0) 推荐(0)
上一页 1 ··· 84 85 86 87 88 89 90 91 92 ··· 119 下一页