当前位置: 首页 > news >正文

天美影视传媒广告制作流程seoul是什么品牌

天美影视传媒广告制作流程,seoul是什么品牌,vue可以做pc的网站,行业网站源码内存管理 new/delete C语言 malloc free完成对堆内存的申请和释放。 C new delete 类 new:动态申请存储空间的运算符,返回值为申请空间的对应数据类型的地址 int *p new int(10); 申请了一个初始值为10的整型数据 int *p new int[10]; 申…

内存管理

new/delete

C语言  malloc  free完成对堆内存的申请和释放。

C++  new  delete 类

new:动态申请存储空间的运算符,返回值为申请空间的对应数据类型的地址

int *p = new int(10);  申请了一个初始值为10的整型数据

int *p = new int[10];   申请了能存放10个整型数据元素的数组,其首地址为arr

单变量空间

#include <iostream>
#include <stdlib.h>
using namespace std;//malloc free  # include <stdlib.h>  库函数
//new delete key work 关键字int main()
{//Cint *p = (int*)malloc(sizeof(int));int *p = static_cast<int*>(malloc(sizeof(int)));//C++  单变量空间int *p = new int(200);//*p = 200;cout<<*p<<endl;string *ps = new string("aaa");//*ps = "china";cout<<*ps<<endl;struct Stu{int age;string name;};Stu *pStu = new Stu{10, "bob"};cout<<pStu->age<<endl;cout<<pStu->name<<endl;return 0;
}

多变量空间  数组

#include <iostream>
#include <string.h>  // #include <cstring>
#include <stdlib.h>
using namespace std;int main()
{char* p = new char[4];const char* source = "aa";strcpy_s(p, 4, source);cout << "p: " << p << endl;int *pi = new int[5]{0};memset(pi, 0, sizeof(int[5]));for(int i = 0; i < 5; i++){cout<<pi[i]<<endl;}char **ppc = new char*[5]{NULL};ppc[0] = new char[10];strcpy(ppc[0], "china");ppc[1] = "automan";ppc[2] = "greatwall";while(*ppc){cout<<*ppc++<<endl;}return 0;
}

一维、多维

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;int main()
{int(*pa)[4] = new int[3][4]{ {0} };for (int i = 0; i < sizeof(int[3][4]) / sizeof(int[4]); i++){for (int j = 0; j < 4; j++){cout << pa[i][j] << "";}cout << endl;}int (*px)[3][4][5] = new int[2][3][4][5];return 0;
}

 内存释放

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;int main()
{int *p = new int;delete p;int *q = new int[1000];delete []q;//多维只用一个框即可,内核用递归删除int *r = new int[1000][][];delete []r;return 0;
}

内联函数

内联函数inline function

介于宏函数和普通函数之间

宏函数

优点:代码内嵌,避免了函数调用。

缺点:容易产生歧义,易使text段体积增大。

普通函数

优点:一段高度抽象的逻辑,不易产生歧义,使text段体积减小。

缺点:函数调用的压栈与出栈的开销。

inline 内联函数

优点:一段高度抽象的逻辑,不易产生歧义,使text段体积减小,会进行类型检查,避免压栈与出栈的开销。

代价:增加代码段的空间

本质:以牺牲代码段空间为代价,提高程序的运行时间的效率

适用:代码体很小且频繁调用

为何不把所有函数inline?

内嵌太多,inline变成了给编译器的一种建议

只有当函数只有10行甚至更少时才会将其定义为内联函数。

#include <iostream>
using namespace std;#define SQR(i) ((i)*(i))  //宏函数int sqr(i)  //普通函数
{return i * i;
}inline int sqr(i)
{return i * i;
}int main()
{int i = 0;while(i < 5){cout<<SQR(i++)<<endl;}return 0;
}

强制类型转换

#include <iostream>
#include <stdlib.h>using namespace std;void func(int & v)
{cout<<v<<endl;
}int main()
{static_cast  对于隐式类型可以转化的,即可用此类型float a = 5.6;int b = 5;//隐式类型转换a = b;b = a;b = static_cast<int>(a);a = static_cast<float>(b);void *p; int *q;p = q;q = p;  //报错q = static_cast<int*>(p);int x = 10;int y = 3;float z = static_cast<float>(x) / y;char * pc = static_cast<char*>(malloc(100));reinterpret_cast  对于无隐式的类型转化,static_cast不可用char * p; int * q;p = reinterpret_cast<char*>(q);int a[5] = {1, 2, 3, 4, 5};int *p = (int*)((int)a+1);int *p = reinterpret_cast<int*>((reinterpret_cast<int>(a) + 1));cout<<hex<<*p<<endl;const_cast  脱常,只能应用于指针和引用const 修饰的一定不可以改const int a = 19;func(const_cast<int&>(a));dynamic_castreturn 0;
}

宏,在预处理阶段发生了替换

常量编译阶段发生了替换

常量不变

命名空间

命名空间为大型项目开发,避免命名冲突的一种机制。

:: 作用域运算符,前面要命名空间

全局无名命名空间

局部

namespace  是对全局命名空间的再次划分。

#include <iostream>using namespace std;int v = 55;  // 全局int main()
{int b = 10;  // 局部int *p = &v;cout<<v<<endl;cout<<b<<endl;cout<<::<<endl;return 0;
}

#include <iostream>using namespace std;namespace Space{int x;void func(){printf("void func");}struct Stu{int a;int b;}
}namespace Other{int x;int y;
}int main()
{Space::x = 200;cout<<Space::x<<endl;using Space::x;x = 20;cout<<x<<endl;using namespace Space;Stu s = {1, 2};cout << s.a << "---" << endl;using namespace Other;Other::x = 10;y = 20;cout<<Other::x<<y<<endl;int m, n;std::cin>>m>>n;std::cout<<m<<n<<std::endl;return 0;
}

如果有局部变量名相同,冲突

支持嵌套

#include <iostream>using namespace std;namespace Space{int a;int b;namespace Other{int m;int n;}
}int main()
{using namespace Space::Other;m = 20;return 0;
}

协作开发

#include <iostream>using namespace std;namespace Space
{int x;
}namespace Space
{int y;
}int main()
{using namespace Space;int x = 10;int y = 20;cout<<x<<y<<endl;return 0;
}

相同空间名会合并

String类

#include <iostream>using namespace std;//string 不是关键字,而是一个类int main()
{std::string str;string str("china");string str = "china";str = "good";string str2(str);cout<<str<<endl;cout<<str2<<endl;string s = "china";s[3] = 'w';cout<<s<<endl;char buf[1024];strcpy(buf, s.c_str());  //string -> char* c_str返回字符串cout<<buf<<endl;str.swap(str2);  //交换两个字符串  swap 成员函数int n = str.find('i', 0); //查找一个字符的位置,返回下标,找不到返回-1cout<<"n = "<<n<<endl;string sArray[10] = {"0","1","22","333","4444","55555","666666","7777777","88888888","999999999",};for(int i = 0; i < 10; i++){cout<<sArray[i]<<endl;}return 0;
}

总结

malloc free C库函数  ;  new delete  new[]  delete[] 关键字

new delete > malloc free

申请单变量空间

申请数组  一维  多维

#include <iostream>using namespace std;struct Str
{char *p;
};int main()
{string *ps = new string;*ps = "china";cout<<ps<<endl;   //输出地址  对象的地址cout<<*ps<<endl;  //输出值    对象的内容struct Str str = {"abcdefg"};int *pi = new int[10]{0};char **ppc = new int*[5]{NULL};  //定义指针数组int (*p)[4] = new int[3][4];return 0;
}

erase(0, npos)

从0开始,一直删除到' '位置

str.erase(0, str.find_first_not_of(' '));

下标后,往后删除

str.erase(str.find_last_not_of(' ') + 1);

#include <iostream>
#include <string.h>
#include <stdlib.h>using namespace std;int main()
{FILE *fp = fopen("aa.txt", "r+");  //打开并读取文件if(fp == NULL)return -1;vector<string> vs;char buf[1024];while(fgets(buf, 1024, fp) != NULL)  //读取文件内容{vs.push_back(buf);  // 内容接在后边}for(int i = 0; i < vs.size(); i++){cout<<vs[i]<<endl;}fclose(fp);return 0;    
}

http://www.dinnco.com/news/15515.html

相关文章:

  • 做网站需要的图片去哪找谷歌官方网站登录入口
  • 广州网站设计公司新闻科技网站建设公司
  • 做网站编辑心得保定seo网络推广
  • 网站 实名认证上海网络推广培训机构
  • 做取名的网站很赚钱吗邯郸网站建设优化
  • 网站换模板有影响吗360投放广告怎么收费
  • 做国外网站衣服码数要怎么写网络营销活动策划
  • 网站建设公司生存关键词排名优化易下拉软件
  • 网站建设 php jsp .net快速排名精灵
  • 局域网网站建设工具秦皇岛百度推广
  • 网站开发支持环境app推广多少钱一单
  • 黄岛网站建设公司哈尔滨关键词排名工具
  • 做名片模板网站百度seo快排软件
  • 泉州网站开发企业长沙优化官网服务
  • 如何自己做优惠卷网站网站制作专业
  • wordpress做复杂网站sem优化技巧
  • 苏州网站建设官网免费web服务器网站
  • 购物网站动态网站设计谷歌搜索为什么用不了
  • 建设网站前的目的微信营销模式
  • 外贸网站开发 河南灵感关键词生成器
  • 做网站后台搭建都用什么新河seo怎么做整站排名
  • 网站套餐报价全国疫情高峰感染进度
  • 酒店为什么做网站网络推广员压力大吗
  • 知名网站建设公司 北京搜索引擎营销怎么做
  • 网站报备查询济南做网站比较好的公司
  • 建设有访问量的网站贵阳做网络推广的公司
  • 服务器网站跳转怎么做百度网页版登录
  • 广州手机网站建设收录好的网站有哪些
  • 网站设计制作托管维护欧美网站建设
  • 做一个卖东西的网站seo是搜索引擎营销