example4_custom_fill_characters.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <iomanip>

int main() {
    bool t = true;
    bool f = false;

    std::cout << "Default boolean output:" << std::endl;
    std::cout << t << " " << f << std::endl;

    std::cout << "\nAlphabetic boolean output:" << std::endl;
    std::cout << std::boolalpha << t << " " << f << std::endl;

    std::cout << "\nCustom-width fields with different fill characters:" << std::endl;
    std::cout << std::setfill('.') << std::left << std::setw(10) << "Name"
              << std::setfill('_') << std::right << std::setw(5) << "Age" << std::endl;

    std::cout << std::setfill('.') << std::left << std::setw(10) << "John"
              << std::setfill('_') << std::right << std::setw(5) << 30 << std::endl;

    return 0;
}
Back to iomanip