随笔分类 - C++
摘要:1 #include 2 #include 3 using namespace std; 4 5 void show(int num) 6 { 7 cout << "int" << endl; 8 } 9 10 void show(int *p) 11 { 12 cout << "int *" << endl; 13 } 14 15 void main...
阅读全文
摘要:C++风格数组 1 #include <iostream> 2 #include <array> 3 using namespace std; 4 5 6 7 void main() 8 { 9 //一维数组 10 //在栈上分配内存 11 //前面是元素类型 12 array<int, 10>my
阅读全文
摘要:1 #include 2 using namespace std; 3 4 template 5 void show(T *p) 6 { 7 //初始化 8 decltype(*p) num(*p); 9 cout << *p << endl; 10 } 11 12 void main() 13 { 14 auto man("2134")...
阅读全文
摘要:1 #include 2 using namespace std; 3 4 template 5 auto add(T1 t1, T2 t2) 6 { 7 return t1 + t2; 8 } 9 10 //auto自适应数据类型,自动推理 11 void main() 12 { 13 auto num = 10; 14 cout << typ...
阅读全文
摘要://默认参数要指定放在右边 1 #include 2 #include 3 using namespace std; 4 5 int add(int a,int b,int c = 1) 6 { 7 return a + b + c; 8 } 9 10 void main() 11 { 12 cout << add(1, 2); 13 14 }
阅读全文
摘要:参数不一致实现printf 1 #include <iostream> 2 #include <cstdarg> 3 using namespace std; 4 5 //递归终止 6 void show(const char *str) 7 { 8 } 9 10 template<typename
阅读全文
摘要:namespace用法示例 1 #include <iostream> 2 using namespace std; 3 4 //定义域名空间 5 namespace myspace 6 { 7 int num = 45; 8 void show() 9 { 10 cout << num << en
阅读全文

浙公网安备 33010602011771号