1. istringstream,ostringstream类
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
class Person
{
private:
string name;
int age;
public:
friend ostream& operator<<( ostream& os, const Person &p ) // 函数2
{
return os << p.name << ' ' << p.age << endl;
}
friend istream& operator>>( istream& in, Person &p ) //函数1
{
return in >> p.name >> p.age;
}
};
int main()
{
string s1 = "hyp 22";
Person a;
istringstream in(s1); // 字符串输入流对象
in >> a; // 会调用函数1,因为istringstream为istream的子类
cout << a;
ostringstream out; // 字符串输出流对象
out << a << endl; //调用函数2,out为ostream的子类
string s2 = out.str(); // 取得字符串
cout << s2 << endl;
system("pause");
return 0;
}
2. 文件IO:#include<fstream>
ifstream fin;文件输入流对象
ofstream fout;文件输出流对象
fstream fio;文件IO对象
都是istream/ostream类的子类,cin/cout能做的事情,文件fin/fout都可以做,文件
输入/输出流对象需要跟一个文件关联
3. 最大的无符号整数可以这样表示:unsigned int num = ~0u;