MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / show

Function show

Exercises/Modules/Chapter 10/Soln10_06.cpp:80–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78
79template <typename T>
80void show(const std::vector<T>& data, size_t width)
81{
82 const size_t data_per_line{ 80 / width - 1};
83 std::cout << std::format("{:{}}", data[0], width); // Output first element
84
85 size_t data_in_line {}; // Number of data in current line
86 for (size_t i {1}; i < data.size(); ++i)
87 {
88 if (++data_in_line == data_per_line)
89 {
90 data_in_line = 0;
91 std::cout << std::endl;
92 }
93 std::cout << std::format("{:{}}", data[i], width); // Output an element
94 }
95 std::cout << std::endl;
96}

Callers 1

mainFunction · 0.70

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected