I want to provide a tab-like capability for C++ text output streams. The feature should allow me to say "note this position", then allow multiple insert operations, and finally allow me to say "add enough fill characters so as to end up N
characters past the originally noted position".
The standard iostream
system does not seem to maintain a column position but I had thought that I could fake it using tellp()
. My assumption was that the difference between tellp()
at two points in my output sequence would correspond to the number of intervening bytes.
Unfortunately, at least in my Gnu C++ environment, cout
does not maintain the fiction of a stream position. Every cout.tellp()
call returns -1
. Why is that?
tellp
is never a column position in any stream. It is only meaningful in seekable streams. – Wanderlusttellp
is supposed to tell you what value to provide toseekp
to get back to the current position. In this case, it's telling you that there is no such possibility. Entabbing has to be supported some other way. – Thrifty