std::ends
來自 cppreference.com
定義於標頭檔案 <ostream> |
||
template< class CharT, class Traits > std::basic_ostream<CharT, Traits>& ends( std::basic_ostream<CharT, Traits>& os ); |
||
將空字元插入到輸出序列 os 中,如同呼叫了 os.put(CharT())。
這是一個僅輸出的 I/O 操縱器,對於任何型別為 std::basic_ostream 的 out
,它都可以透過諸如 out << std::ends 的表示式來呼叫。
目錄 |
[編輯] 注意
此操縱器通常與 std::ostrstream 一起使用,當關聯的輸出緩衝區需要以空字元結尾才能作為 C 字串處理時。
與 std::endl 不同,此操縱器不會重新整理流。
[編輯] 引數
os | - | 輸出流的引用 |
[編輯] 返回值
os(插入空字元後流的引用)。
[編輯] 示例
執行此程式碼
#include <cstdio> #include <strstream> int main() { std::ostrstream oss; oss << "Sample text: " << 42 << std::ends; std::printf("%s\n", oss.str()); oss.freeze(false); // enable memory deallocation }
輸出
Sample text: 42
[編輯] 參閱
(在 C++98 中已廢棄)(在 C++26 中已移除) |
實現字元陣列輸出操作 (類) |