1.fin.gcount();读取到的字节数
2.fin.read((char*)地址, 字节数); 不会自动加'\0'
3.fin.eof();是否读到文件末尾,end of file
4.width(1),指定小时按实际宽度输出,一次性,只对下一个输出有效
5.fill('*');永久有效:cout.width(10); cout.fill('*'); cout<<123<<endl;
6.输出格式控制符:cout<<wf(10, '*')<<100<<endl;
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class wf
{
int w;
char f;
public:
wf(int w, char f):w(w), f(f){}
friend ostream& operator<<(ostream&, const wf&);
};
ostream& operator<<(ostream& os, const wf& w)
{
os.width(w.w);
os.fill(w.f);
return os;
}
int main()
{
cout<<wf(10, '*')<<100<<endl;
system("pause");
return 0;
}
7.cout.precision(8);控制精度,最后一位四舍五入
8.cout.setf(ios::left); right, dec(10), oct(8), hex(16), showbase(前缀),showpoint(总是带小数点), uppercase(大写0X, A-F, E), showpos(positire带符号),scientific(科学计数法5.168E-6)
9.cout默认6位输出
10.cout.precision(2); cout.setf(ios::fixed); 小数点后精度
11.unsetf(ios::xx); 取消设置
12.使用cout.set(ios::hex),要cout.unsetf(ios::dec|ios::oct);
13.endl = \n + flush;cout<<flush;
14. 格式控制符都可以使用cout<<oct|dec|hex<<i<<endl;
15.格式控制函数对应的格式控制符<iosmanip> cout<<setw(宽度); cout<<setfill('*'); cout<<setprecision(8);
16.ofstream.fout(filename); 默认清除文件中的原有内容
17.fout(filename, ios::out(默认-写));可用ios::app追加,ios::binary二进制打开文件
18.win中以文本方式打开文件而不是二进制打开文件时,写'\n'时改为'\r''\n',读到'\r''\n'时改为'\n'。
19.fout.seekp(位置int);写put。fin.seekg(位置int);读get。
20.取得当前读位置fin.tellg();当前写位置fout.tellp();
21.读写打开文件fstream fio(filename, ios::in|ios::out|ios::binary);类继承关系 istream->ifstream, ostream->ofstream, istream/ostream->iostream->fstream。
22.内部类:成员内部类、局部内部类,作用域有限。①隐藏名字,避免类名冲突②通过提供统一内部类名来统一各个类的操作方法
23.成员内部类使用:
class A{
public:
class B{};
};
int main()
{
A::B b;
}
24.try{throw 变量;} catch(变量类型){} catch (变量类型){}
25.如果没有catch能够处理,退出不处理后面内容
26.catch(...){}接收任何类型
27.typedef int T; struct Node{T date; Node *next;};
28.基本类型() = 0;