> Is there some standard) way to make ostream automatically insert
whitespace character after something is inserted into stream using
operator <<?
For example:
int x=10, y=20, z=30;
ofs << "(" << x << y << z << ")\n";
should yield "(10 20 30)" - not "(102030)". My current way around this
induces very messy code, especially when there are more than three
variables written at once:
ofs << "(" << x << " " << y << " " << z << ")\n";
You can do
ofs << '(' << x << ' ' << y << ' ' << z << ")\n";
which is more economical than quoted strings. I use single characters where
the quoted string being output is just a single character.
Apart from this, you can use ostream_iterator if your x, y,z are in an
array. So
vector <int> coords1;
int coords2[3];
:
ofs << '(';
copy(coords1.begin(), coords1.end(), ostream_iterator<int>(ofs, " "));
ofs << ")\n";
or (I have not tested this out to see if this compiles but I think so)
ofs << '(';
copy(&coords2[0], &coords2[3], ostream_iterator<int>(ofs, " "));
ofs << ")\n";
The " " adds a space between elements of an array
with the appropriate headers and "using namespace std;"
Stephen Howe