strstreamで紐付けられたバッファにアクセスするには、メンバ関数str()を使う。
std::strstream::str - cppreference.com
今回は、紐付けたbufに続いて、str()で取得した文字列も出力する。
これで実行すると、
$ vi strstream.cpp $ g++ strstream.cpp -o strstream In file included from /usr/include/c++/8/backward/strstream:50, from strstream.cpp:4: /usr/include/c++/8/backward/backward_warning.h:32:2: 警告: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp] #warning \ ^~~~~~~ $ ./strstream buf = ABC ss.str() = ABC $
このように、どちらも"ABC"が出力されている。
Sample/cpp/strstream/str/src/strstream at master · bg1bgst333/Sample · GitHub