
C++
SZTLLDGZ
这个作者很懒,什么都没留下…
展开
-
(1)bool类型
#include <iostream>using namespace std;int main(){ bool istrue = false; cin >> istrue; if (istrue) { cout << "true" << endl; } else { cout << "false"原创 2018-07-17 18:59:47 · 434 阅读 · 0 评论 -
(11)类外定义
//同文件类外定义:#include <iostream>#include <string>using namespace std;class student{public: void setName(string _name); string getName(); void setGender(string _gender); string get...原创 2018-07-18 17:38:22 · 382 阅读 · 0 评论 -
(10)数据封装与类内定义
#include <iostream>#include <string>using namespace std;//面向对象的基本思想:谁做什么//代码:将所有的数据操作转化为成员函数的调用// 换句话说对象在程序中的所有行为都通过调用自己的函数来完成//用函数来封装数据成员://1.可以对传入进来的参数起到条件限制的作用//2.只读属性(不希望外界...转载 2018-07-18 17:26:38 · 246 阅读 · 0 评论 -
(9)string
#include <iostream>#include <string>using namespace std;/*string 类型初始化string对象的方式:string s1 s1为空串string s2("ABC") 用字符串字面值初始化s2string s3(s2) 将s3初始化为s2的一个副本string s4(n, 'c')...原创 2018-07-18 17:25:45 · 239 阅读 · 0 评论 -
(8)类和对象
#include <iostream>using namespace std;//注释部分会有点乱,是因为直接从vs粘贴过来的,复制到vs里就可变得正常//类 | class TV//目的不同抽象出的信息不同 | {//选择性的暴露 访问限定符public protected private | public:// ...翻译 2018-07-18 17:23:21 · 198 阅读 · 0 评论 -
(7)内存管理(new、delete)
#include <iostream>using namespace std;//内存管理//内存的本质是资源,由操作系统掌管内存资源//申请/归还内存资源就是内存管理//申请内存:运算符new:int*p = new int;int *arr = new int[10];/*申请内存需要判断是否成功int *p = new int[1000];if (NULL ...原创 2018-07-17 19:05:09 · 246 阅读 · 0 评论 -
(6)函数特性(函数参数默认值、函数重载、内联函数)
#include <iostream>using namespace std;//函数参数默认值 实参覆盖默认值//有默认值的参数必须在参数表的最右端//声明的时候写默认值,定义的时候不写默认值,这样所有的编译器都能通过//无实参则用默认值,否则实参覆盖默认值//函数重载 名称相同参数可辨//在相同作用域内//用同一函数名定义的多个函数 参数个数和参数类型不同 这...转载 2018-07-17 19:04:31 · 208 阅读 · 0 评论 -
(5)const
#include <iostream>using namespace std;#define X 3 //const相比于define的好处是有类型的,在编译的时候要检查语法错误void fun(const int &a, int const &b){ //a = 10; 报错 //b = 20; 报错}int main(){ int cons...翻译 2018-07-17 19:03:32 · 215 阅读 · 0 评论 -
(4)引用
//引用是变量的别名,而且引用不能单独存在#include <iostream>using namespace std;typedef struct A{ int x; int y;}co;void fun(int &a, int &b){ int c = 0; c = a; a = b; b = c; return;}int m...转载 2018-07-17 19:02:54 · 151 阅读 · 0 评论 -
(3)命名空间
#include <iostream>using namespace std;namespace a{ int x(1); void fun() { std::cout << "a" << endl; }}namespace b{ int x(2); void fun() { cout << "b" <&a转载 2018-07-17 19:01:46 · 168 阅读 · 0 评论 -
(2)进制转换
#include <iostream>using namespace std;int main(){ int x(10); cout << oct << x << endl; cout << dec << x << endl; cout << hex <&翻译 2018-07-17 19:00:50 · 294 阅读 · 0 评论 -
(12)构造函数
main.cpp#include <iostream>#include <string>#include "student.h"using namespace std;/*内存分区:(按照用途划分)栈区:int x = 0;int *p = NULL;即定义变量存储在栈区,内存由系统进行控制,无论是分配还是回收都不需要程序员来关心堆区:int *p...原创 2018-09-18 16:33:31 · 223 阅读 · 0 评论