std::ends(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay so this is the <pink>std::ends(3)</pink> page from the C++ Standard Libary β€” manual name folded in right at the top, no boring header-line copy, we move. πŸ’…

  • std::ends β€” std::ends β€” yes bestie, the NAME is literally std::ends - std::ends.

✨ Synopsis ✨

Defined in header <ostream> ✨

template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>& ends( std::basic_ostream<CharT, Traits>& os );

It inserts a null character into the output sequence os as if by calling os.put(CharT()). Literally that. 🫢

This is an output-only I/O manipulator, and it may be called with an expression such as out << std::ends for any out of type std::basic_ostream. Slay. πŸ’…

🌸 Notes 🌸

This manipulator is typically used with std::ostrstream, when the associated output buffer needs to be null-terminated to be processed as a C string.

Unlike std::endl, this manipulator does not flush the stream. Important bestie behavior. 😭

πŸŽ€ Parameters πŸŽ€

  • os β€” reference to output stream.

πŸ’– Return value πŸ’–

os (reference to the stream after insertion of the null character). Yup, it hands you back the stream. 🫢

πŸ¦‹ Example πŸ¦‹

Run this code, bestie:

// Run this code

#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
}

πŸ“ Output πŸ“

Sample text: 42

🌈 See also 🌈

  • ostrstream β€” implements character array output operations (deprecated in C++98) (class) (removed in C++26). iconic but also deprecated/removed, iykyk πŸ’€

xoxo, source: http://cppreference.com, version/date: 2024.06.10, page: std::ends(3) β€” byeeee πŸ«ΆπŸ’–

πŸ“¦ where this page comes from