From 86c9f2966dd93b9bc17c48c88d2faa92cd94b771 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Wed, 25 Jul 2018 16:45:38 -0300 Subject: Simpler output impl. sparkify() now receives generic ostream as argument; pass std::cout as arg to sparkify() in main. --- src/main.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 95b9140..8291db2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include const char *TICKS[] = {"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"}; @@ -10,7 +9,7 @@ const size_t NUM_TICKS = 8; const double EPSILON = 1e-8; template -void sparkify(const std::vector &values, std::ostringstream &out) { +void sparkify(const std::vector &values, std::ostream &out) { auto minmax = std::minmax_element(values.begin(), values.end()); auto min = *minmax.first, max = *minmax.second; @@ -30,7 +29,6 @@ void sparkify(const std::vector &values, std::ostringstream &out) { int main() { std::vector values; - std::ostringstream out; for (double value; std::cin >> value;) { values.push_back(value); } @@ -42,7 +40,7 @@ int main() return 0; } - sparkify(values, out); - std::cout << out.str() << std::endl; + sparkify(values, std::cout); + std::cout << std::endl; return 0; } -- cgit v1.2.3