Why does cout.tellp always return -1?

I want to provide a tab for C ++ text output streams. The function should allow me to say “mark this position,” then allow several insert operations, and finally let me say “add enough padding characters so that eventually there are Ncharacters that have passed the originally marked position.”

The standard system iostreamdoes not seem to support the column position, but I thought I could fake it using tellp(). My assumption was that the difference between tellp()the two points in my output sequence would correspond to the number of intermediate bytes.

Unfortunately, at least in my environment, Gnu C ++ coutdoes not support thread position fiction. Every challenge cout.tellp() returns -1. Why is this?

+5
source share
1 answer

tellp returns the position in the stream so you can search for it. The console does not allow searching. In addition, even you interpret the position as "the number of bytes written to the stream since it was created", this number will not be used to position the cursor - the screen wraps around, its width is usually unpredictable. You simply won’t know which column you are in, since the row length is variable.

, ANSI , . .

http://ascii-table.com/ansi-escape-sequences.php

+2

All Articles