C ++でstringstreamを使用する方法と例



How Use Stringstream C






上記は、C ++の入力ストリームと出力ストリームの間のいくつかの関係です。

istringstreamは文字列オブジェクトから構築され、文字列オブジェクトから文字を読み取ります。に
ostringstreamも文字列オブジェクトから構築され、文字列オブジェクトに文字を挿入します。



stringstreamは、C ++スタイルの文字列の入力と出力に使用されます。

関数パラメーターを無視する:読み取る必要のある文字列の最大長、無視する必要のある文字




テストコード:

#include using namespace std void usestringstream() { // usage of stringstream stringstream ss string s int i = 1234 ss <> s cout << s <> s) { cout << s << endl } iss.clear() } void useostringstream() { //Usage of ostringstream ostringstream out out.put('t')//Insert character out.put('e') out << 'st' string res = out.str()//Extract string cout << res << endl } int main() { usestringstream() useristringstream() useostringstream()//output test return 0 }