//This file is main.C (C++ example). #include #include #include #include #include //for fill #include "printable.h" #include "terminal.h" using namespace std; int main() { srand(static_cast(time(0))); const terminal term('.'); const terminal::offset_type off(term.width(), term.height()); terminal::iterator it = term.begin(); string s = "Spiral iterators (counterclockwise)."; copy(s.begin(), s.end(), it); s = "Please type printable characters ending with a q: "; copy(s.begin(), s.end(), it + terminal::offset_type::down()); s = "abcdefghijklmnopqrstuvwxyz"; //Spiral centered out in the middle it = terminal::iterator(&term, 3, 5); terminal::spiral_iterator sit = it; for (int i = 0; abs(sit) <= 3; ++i, ++sit) { *sit = s[i]; } //Spiral centered at upper right corner of screen sit = term.begin() + term.width() - 1; for (int j = 0; j < s.size(); ++j, ++sit) { *sit = s[j]; } //Spiral centered at center of right edge of screen. sit = terminal::iterator(&term, term.width() - 1, term.height() / 2); for (int j = 0; j < s.size(); ++j, ++sit) { *sit = s[j]; } sit = term.begin() + off / 2; *sit++ = 'X'; for (;;) { char c; //uninitialized variable while ((c = term.key()) == '\0') { } if (c == 'q') { break; } try { *sit = c; ++sit; } catch (const printable::isnt&) { term.beep(); } } return EXIT_SUCCESS; }