程序设计与算法(三)C++面向对象程序设计 第七周 相关笔记
2021/10/23 11:10:15
本文主要是介绍程序设计与算法(三)C++面向对象程序设计 第七周 相关笔记,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、cerr
freopen cout输出到文件内时,cerr能输出到控制台显示
2、cin.getline()
defalut -> '\n'
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> using namespace std; int main(){ //IOS; //freopen("a.txt","r",stdin); char a[1000]; while(cin.getline(a,23333,',')){ cout<<a<<endl; } return 0; } 输出: 123,124,124,124, 123 124 124 124View Code
3、cin.peek()提前读入一个字符,但不从输入流中去掉
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> using namespace std; int main(){ //IOS; //freopen("a.txt","r",stdin); ; if(isdigit(cin.peek())){ int a; cin>>a; cout<<a<<endl; } else{ char a[10]; cin>>a; cout<<a<<endl;; } return 0; }View Code
4、cin.petback('c')将字符放回输入流前面
5、cin.ignore(ncount,delim = 'eof')忽略n个字符,遇到delim结束
6、流操作算子
7、template<class T1,class T2 ....>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> using namespace std; template<class T> void Swap(T & a,T & b){ T tmp = a; a = b; b = tmp; } int main(){ int a = 1,b = 2; double c = 0.4,d = 12.4; Swap(a,b); Swap(c,d); cout<<a<<" "<<b<<endl<<c<<" "<<d<<endl; // Swap(b,c)报错 return 0; }View Code
可重载
8、
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<bits/stdc++.h> using namespace std; template<class T1,class T2,class T3> void Map(T1 begin,T1 end,T2 pur,T3 opt){ for(T1 t = begin;t!=end;++t,++pur){ *pur = opt(*t); } } int opt1(int x){ return x*x; } double opt2(int x){ return sqrt((double)x); } int main(){ int a[5] = {1,2,3,4,5}; double b[5];int c[5]; Map(a,a+5,c,opt1); Map(a,a+5,b,opt2); for(int i = 0;i<5;++i)cout<<b[i]<<" "; cout<<endl; for(int i = 0;i<5;++i)cout<<c[i]<<" "; cout<<endl; } 输出: 1 1.41421 1.73205 2 2.23607 1 4 9 16 25View Code
9、类模板:略
这篇关于程序设计与算法(三)C++面向对象程序设计 第七周 相关笔记的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-08测试人员在 Scrum 中的角色是什么?
- 2024-07-07Dify + TiDB Vector,快速构建你的AI Agent
- 2024-07-06有没有什么开源的py项目可以对图像进行分类-icode9专业技术文章分享
- 2024-07-05feign默认connecttimeout和readtimeout是多少-icode9专业技术文章分享
- 2024-07-05idea控制台,日志太多,导致部分想看得日志被刷走 搜不到-icode9专业技术文章分享
- 2024-07-05The server selected protocol version Tls10 is not accepted by client preferences [TLs12]-icode9专业技术文章分享
- 2024-07-05怎么清理项目缓存-icode9专业技术文章分享
- 2024-07-04安装 Eyoucms详细图文教程-icode9专业技术文章分享
- 2024-07-04ueditor 复制文章时,图片的链接是一个下载图片地址,该如何处理?-icode9专业技术文章分享
- 2024-07-04怎样判断host有没有对wordpress有缓存呢-icode9专业技术文章分享