std::setfill(3)

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

πŸ’– std::setfill(3) β€” C++ Standard Library πŸ’–

okay so this is the manual page for std::setfill, and yes the NAME is literally std::setfill β€” std::setfill. iconic, no notes. πŸ’…


πŸŽ€ NAME πŸŽ€

std::setfill β€” std::setfill

✨ Synopsis ✨

Defined in header <iomanip>:

template< class CharT >
/*unspecified*/ setfill( CharT c );

When it’s used in an expression like out << setfill(c), it sets the fill character of the stream out to c. slay ✨

🌸 Parameters 🌸

  • c β€” new value for the fill character. that’s the whole parameter, bestie 🫢

πŸ’« Return value πŸ’«

An object of unspecified type such that:

  • if out is an object of type std::basic_ostream<CharT, Traits>, the expression out << setfill(c)
    • has type std::basic_ostream<CharT, Traits>&
    • has value out
    • behaves as if it called f(out, c)

where the function f is defined as:

template<class CharT, class Traits>
void f(std::basic_ios<CharT, Traits>& str, CharT c)
{
    // set fill character
    str.fill(c);
}
lowkey important: the return type is unspecified, so don’t go trying to name it, okay? iykyk πŸ’€

πŸ¦‹ Notes πŸ¦‹

The current fill character may be obtained with std::ostream::fill. tiny but useful πŸ“

🌈 Example 🌈

Run this code, bestie:

#include <iomanip>
#include <iostream>

int main()
{
    std::cout << "default fill: [" << std::setw(10) << 42 << "]\n"
              << "setfill('*'): [" << std::setfill('*')
                                   << std::setw(10) << 42 << "]\n";
}

⭐ Output ⭐

default fill: [        42]
setfill('*'): [********42]

🩹 Defect reports 🩹

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • DR: LWG 183
  • Applied to: C++98
  • Behavior as published: setbase could only be used with streams of type std::ostream
  • Correct behavior: usable with any output character stream

look at that glow-up ✨

πŸ‘€ See also πŸ‘€

  • fill β€” manages the fill character (public member function of std::basic_ios<CharT,Traits>)
  • internal β€” sets the placement of fill characters
  • left β€” (function)
  • right β€” (function)
  • setw β€” changes the width of the next input/output field (function)

okay that’s the whole page, bestie πŸ’… β€” the footer energy is from http://cppreference.com, version 2024.06.10, and this is the std::setfill(3) page. mwah πŸ«ΆπŸ’–

πŸ“¦ where this page comes from