省去临时对象的构造和析构过程,从而提高效率
对象 过程 构造 临时 提高效率 从而 和析构
2023-09-14 09:12:04 时间
如果输入参数以值传递的方式传递对象,则宜改用“const &”方式来 传递,这样可以省去临时对象的构造和析构过程,从而提高效率。
1 #include <iostream> 2 #include<stdlib.h> 3 #define MAX 30 4 //main()的定义 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 6 using namespace std; 7 int main(int argc, char** argv) { 8 char str[MAX],*p; 9 10 //从键盘上输入int数 11 cout<<"Please input a int:"<<endl; 12 int n; 13 cin>>n; 14 15 //将整型数n按十进制转换为字符串并输出 16 p=itoa(n,str,10); 17 cout<<"str="<<str<<endl; 18 cout<<"p="<<p<<endl; 19 20 //将整型数n按十六进制转换为字符串并输出 21 p=itoa(n,str,16); 22 cout<<"str="<<str<<endl; 23 cout<<"p="<<p<<endl; 24 25 //从键盘上输入double类型的数据 26 cout<<"Please input a double:"<<endl; 27 double x; 28 cout<<"x="; 29 cin>>x; 30 31 //将浮点数x转换为字符串后输出 32 p=gcvt(x,10,str); 33 cout<<"str="<<str<<endl; 34 cout<<"p="<<p<<endl; 35 36 return 0; 37 return 0; 38 }
相关文章
- java IO之 序列流 集合对象Properties 打印流 流对象
- Java反射获取对象中的所有元素(代码库)
- 查看 js对象
- jQuery获取对象简单实现方法
- JSON和对象之前的相互转换
- Python Django HttpResponse响应对象
- JVM对象分配过程详解.png
- JVM调优:图解对象内存分配过程
- 为什么Spartacus单元测试里对http返回的Observable对象调用subscribe时,会触发依赖注入的框架代码
- jQuery对象入门级介绍
- android8.0 Launcher源码(8)---Launcher的源码启动过程创建Launcher辅助对象
- 100天精通Python(数据分析篇)——第55天:Pandas之DataFrame对象基础大总结
- Python编程:利用上下文管理器管理MySQL的链接对象
- (三十六)类数组对象arguments
- C++使用技巧(二十八):回顾内存new关键字、引用、默认参数、 占位参数、重载、类和对象、构造函数
- 开发过程是用对个简单的对象的多个简单的方法,来实现复杂的功能
- 有关对象指针的使用方法