達内2013 C++チュートリアルノート(実はそのデータ結果とアルゴリズムの一部ですが、内容はC++のようです)
1177 ワード
1.istringstream、ostringstreamクラス
2.ファイルIO:#includeifstream fin;ファイル入力ストリームオブジェクトofstream fout;ファイル出力ストリームオブジェクトfstream fio;ファイルIOオブジェクトはすべてistream/ostreamクラスのサブクラスで、cin/coutができること、ファイルfin/foutはすべてすることができて、ファイルの入出力ストリームオブジェクトは1つのファイルに関連する必要があります3.最大の符号なし整数は、unsigned int num=~0 u;
#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