Aligned plain-text table for terminal output

C++
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

void printTable(const std::vector<std::vector<std::string>>& rows) {
    if (rows.empty()) return;
    std::size_t cols = rows[0].size();
    std::vector<std::size_t> w(cols, 0);
    for (const auto& r : rows) for (std::size_t c = 0; c < cols && c < r.size(); ++c) w[c] = std::max(w[c], r[c].size());
    auto line = [&](const std::vector<std::string>& r) {
        for (std::size_t c = 0; c < cols; ++c) std::cout << std::left << std::setw(int(w[c]) + 2) << (c < r.size() ? r[c] : "");
        std::cout << '\n';
    };
    line(rows[0]);
    for (std::size_t c = 0; c < cols; ++c) std::cout << std::string(w[c] + 2, '-');
    std::cout << '\n';
    for (std::size_t i = 1; i < rows.size(); ++i) line(rows[i]);
}