随笔分类 -  C++日常学习

摘要:1 #include <iostream> 2 #include <string> 3 using namespace std; 4 //汽车类 5 class Car 6 { 7 public: 8 Car(); 9 Car(string name) 10 { 11 cout << "Car带参构 阅读全文
posted @ 2021-03-13 18:14 丁帅帅dss 阅读(88) 评论(0) 推荐(0)
摘要:1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 class Person 5 { 6 public: 7 Person() 8 { 9 cout << "无参构造" << endl; 10 } 11 Person 阅读全文
posted @ 2021-03-13 18:13 丁帅帅dss 阅读(61) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstring> using namespace std; class Person { public: Person() { cout << "构造函数调用" << endl; pName = (char *)malloc(sizeof( 阅读全文
posted @ 2021-03-13 18:12 丁帅帅dss 阅读(64) 评论(0) 推荐(0)
摘要:1 #include<iostream> 2 using namespace std; 3 class Point 4 { 5 public: 6 void setX(int x) 7 { 8 mX = x; 9 } 10 void setY(int y) 11 { 12 mY = y; 13 } 阅读全文
posted @ 2021-03-13 18:11 丁帅帅dss 阅读(144) 评论(0) 推荐(1)
摘要:1 //设计立方体类(Cube),求出立方体的面积(2 * a*b + 2 * a*c + 2 * b*c)和体积(a * b * c), 2 //分别用全局函数和成员函数判断两个立方体是否相等。 3 #include <iostream> 4 using namespace std; 5 clas 阅读全文
posted @ 2021-03-13 18:10 丁帅帅dss 阅读(129) 评论(0) 推荐(0)
摘要:#include <iostream> #include <string> using namespace std;int main(){ string s = "abc"; /*for (int i=0;i!=s.size();++i) { cout << s[i]; }*/ /*for (int 阅读全文
posted @ 2020-12-09 23:04 丁帅帅dss 阅读(596) 评论(0) 推荐(0)
摘要:在C语言中,动态分配内存用 malloc() 函数,释放内存用 free() 函数。如下所示: int *p = (int*) malloc( sizeof(int) * 10 ); //分配10个int型的内存空间 free(p); //释放内存. 在C++中,这两个函数仍然可以使用,但是C++又 阅读全文
posted @ 2020-12-03 22:14 丁帅帅dss 阅读(257) 评论(0) 推荐(0)
摘要:1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 using namespace std; 5 int main() 6 { 7 int a = 10; 8 int b = 5; 9 int c = 12; 10 s 阅读全文
posted @ 2020-12-02 22:34 丁帅帅dss 阅读(89) 评论(0) 推荐(0)
摘要:1 #include <iostream> 2 using namespace std; 3 int abc(int); 4 int fun1(int); 5 int fun1(int a) 6 { 7 cout << "递归函数1" << endl; 8 if (a == 1) 9 { 10 re 阅读全文
posted @ 2020-12-02 00:37 丁帅帅dss 阅读(82) 评论(0) 推荐(0)
摘要:1 //1.sort函数排序 2 /* 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 int main() 7 { 8 int a[] = { 2,0,3,1,8,2,4,0 }; 9 sort(a, a 阅读全文
posted @ 2020-11-22 09:40 丁帅帅dss 阅读(98) 评论(0) 推荐(0)
摘要:1 /* 2 #include <iostream> 3 using namespace std; 4 float Div(int a, int b) 5 { 6 if (b==0) 7 { 8 throw b;//抛出异常 9 } 10 return a*1.0 / b; 11 } 12 int 阅读全文
posted @ 2020-11-22 09:38 丁帅帅dss 阅读(69) 评论(0) 推荐(0)