流类体系
输入输出流
- ? ostream类
cout cerr clog ciin 字符类的处理
? 正常的操作
? 调用成员函数的方式
格式控制字符
istream 类 cin
#include <iostream>
#include <cstdio>
#include<iomanip>
using namespace std;
void testostream()
{
cout << "标准输出" << endl;
cerr << "标准错误输出" << endl;
clog << "标准错误输出" << endl;
cout.put('a');
cout << 'a' << endl;
char c = 'C';
cout.put(c);
cout << c << endl;
cout.write("Iloveyou", 4);
cout.put(cin.get());
while (cin.get() != '\n');
char str[20] = "";
cin.getline(str, 20);
cout.write(str, 20);
}
void testiomanip()
{
double pi = 34.12343;
cout << "设置有效位数是:" << setprecision(4) <<pi<< endl;
cout <<"有效小数位:"<< fixed << setprecision(4) << pi << endl;
cout << hex << 32 << endl;
cout << oct << 15 << endl;
cout << setbase(16) << 15 << endl;
cout << setiosflags(ios::left);
cout << setw(8) << "123" << setw(8) << "1234" << setw(8) << "3444" << endl;
cout << setw(8) << "123" << setw(8) << "1234" << setw(8) << "3444" << endl;
}
int main()
{
testiomanip();
return 0;
}
字符流
文件流
|