1、cerr
freopen cout输出到文件内时,cerr能输出到控制台显示
2、cin.getline()
defalut -> '\n'
#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()提前读入一个字符,但不从输入流中去掉
#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 ....>
#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、
#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、类模板:略