std::ios_base::width (3) - Linux Manuals
std::ios_base::width: std::ios_base::width
Command to display std::ios_base::width
manual in Linux: $ man 3 std::ios_base::width
NAME
std::ios_base::width - std::ios_base::width
Synopsis
streamsize width() const; (1)
streamsize width( streamsize new_width ); (2)
Manages the minimum number of characters to generate on certain output operations and the maximum number of characters to generate on certain input operations.
1) Returns the current field width.
2) Sets the field width to the given one. Returns the previous field width.
Parameters
new_width - new field width setting
Return value
The field width before the call to the function
Notes
Some I/O functions call width(0) before returning, see std::setw (this results in this field having effect on the next I/O function only, and not on any subsequent I/O)
The exact effects this modifier has on the input and output vary between the individual I/O functions and are described at each operator<< and operator>> overload page individually.
Example
// Run this code
#include <array>
#include <tuple>
#include <ctime>
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
int main()
{
auto str_time = [](int year, int mon, int day)
{
constexpr std::array<const char*, 7> week_day{ {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
} };
std::tm tm{};
tm.tm_year = year - 1900;
tm.tm_mon = mon - 1;
tm.tm_mday = day;
day += mon < 3 ? year-- : year - 2;
tm.tm_wday = (23 * mon / 9 + day + 4 + year / 4 - year / 100 + year / 400) % 7;
std::ostringstream out;
out << week_day[tm.tm_wday] << ", " << std::put_time(&tm, "%B %d, %Y");
return out.str();
};
constexpr int column_size = 4;
using table_t = std::array<std::string, column_size>;
table_t headers{ { "Name", "Birthdate", "Death date", "Language Created" } };
std::array<table_t, 5> data{ {
{ { "Dennis MacAlistair Ritchie", str_time(1941, 9, 9), str_time(2011, 10, 12), "C" } },
{ { "Bjarne Stroustrup", str_time(1950, 12, 30), "", "C++" } },
{ { "Anders Hejlsberg", str_time(1960, 12, 2), "", "C#" } },
{ { "Guido van Rossum", str_time(1956, 1, 31), "", "Python" } },
{ { "Brendan Eich", str_time(1961, 7, 4), "", "Javascript" } }
} };
constexpr int name_wid = 30;
constexpr int birth_wid = 30;
constexpr int death_wid = 30;
constexpr int lang_wid = 18;
auto print_line = [](table_t const &tbl)
{