ends

strstreamでNULL終端していない場合は、endsを出力することでNULL終端する。

ends - cpprefjp C++日本語リファレンス

前回のプログラムに、endsの処理を追加する。

このようにする。

$ vi ends.cpp
$ g++ ends.cpp -o ends
In file included from /usr/include/c++/8/backward/strstream:50,
                 from ends.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 \
  ^~~~~~~
$ ./ends
buf = ABC
$

今度は、"ABC"で終わっている。

Sample/cpp/ends/ends/src/ends at master · bg1bgst333/Sample · GitHub