"Jon Bell" <jt*******@presby.edu> wrote in message:
tomakated <to*******@comcast.net> wrote:
How about this?
cout << " | | \n"
<< "---+---+---\n"
<< " | | \n"
<< "---+---+---\n"
<< " | | \n";
To generalize this a bit, if Tic Tac Toe boards are represented as instances of
vector< vector<char> >, you can do something like this:
#include <iostream>
#include <vector>
#include <boost/assign.hpp>
#include <boost/iostreams/format_lite.hpp>
int main()
{
using namespace std;
using namespace boost::io;
using namespace boost::assign;
typedef vector<char> row;
typedef vector<row> board;
board b =
list_of( list_of('X')(' ')('O') )
( list_of('O')('O')('X') )
( list_of('X')(' ')('X') );
std::cout << punctuate<row>(" ", " | ", " ")
<< punctuate< vector<_> >("", "\n---+---+---\n", "")
<< b;
}
Output (view with fixed-width font):
X | | O
---+---+---
O | O | X
---+---+---
X | | X
Here I'm using the new Boost Assign library to initialize the board, and my
Format Lite library to format it. (See
http://home.comcast.net/~jturkanis/format_lite/)
Of course, this might be using a sledge hammer to kill a mosquito -- or, to use
a phrase I am trying to popularize -- using a daisy-cutter to cut a daisy.
Jonathan