Browse code

Buffer printing

Robert Cranston authored on 21/05/2025 01:54:54
Showing 2 changed files

... ...
@@ -4,7 +4,7 @@ A simple C++11 command line maze generator.
4 4
 
5 5
 Features:
6 6
 
7
--   Printing
7
+-   Printing (with buffering)
8 8
 -   Callback during generation
9 9
 -   Algorithms
10 10
     -   Hunt And Kill
... ...
@@ -2,6 +2,7 @@
2 2
 #include <cstdlib>
3 3
 #include <ctime>
4 4
 #include <iostream>
5
+#include <sstream>
5 6
 #include <thread>
6 7
 #include <vector>
7 8
 
... ...
@@ -36,9 +37,11 @@ struct Maze
36 37
     }
37 38
     void print() const
38 39
     {
39
-        for (auto y = 0; y < h; ++y, std::cout << '\n')
40
+        std::ostringstream oss;
41
+        for (auto y = 0; y < h; ++y, oss << '\n')
40 42
         for (auto x = 0; x < w; ++x)
41
-            std::cout << (cells[w * y + x] == PATH ? "  " : "██");
43
+            oss << (cells[w * y + x] == PATH ? "  " : "██");
44
+        std::cout << oss.str();
42 45
     }
43 46
     int w;
44 47
     int h;