473,320 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

std out question

maybe this is more an iostream question.

I would like to output a value to a console in the following manner:

value: xx

Where xx gets updated dynamically. Is it possible using std C++ to back
up to a certain position for output? (Is it clear what I'm asking
for?). Something to do with an output stream and backup up the output
stream?

Any advice would be appreciated.

Glen
Jul 22 '05 #1
7 1359
* glen_stark <st***@ifh.ee.ethz.ch> schriebt:
maybe this is more an iostream question.

I would like to output a value to a console in the following manner:

value: xx

Where xx gets updated dynamically. Is it possible using std C++ to back
up to a certain position for output?


C++ provides no such facility. That would be OK, except C++ also actively
sabotages the facility that in practice is universally available, namely
the ASCII carriage return character (ASCII character 13, which is denoted by
'\r' in C++ (but note that '\r' is not necessarily denoted by ASCII 13)).
The sabotage takes the form of possible translation of the carriage return
character, and that this possible translation can not be turned off for
the standard named iostreams, although it can be turned off for other streams.

As a consequence of that sabotage you cannot, in standard C++, write a program
that copies its standard input exactly to its standard output, like 'cat'.

I think that's horrible, but whenever it has been mentioned a very large flock
of C++ zealots have descended on the thread in question, so it's a bit touchy.

If your output is to a typical (?) text terminal, however, you can probably
use an escape sequence. Such sequences vary from terminal to terminal, but
there is an ANSI standard. If I recall correctly you'd output ASCII 27, the
escape character, followed by '[', followed by e.g. 'H' to move the text
cursor to the upper left corner of the screen -- and other sequences to
move it elsewhere, set colors, etc.

Possibly, if your output is to an emulation of a terminal in a GUI window, it
might be possible to use an ANSI driver in between your program output and the
actual presention -- e.g. there was such a driver, called ansi.sys, in
16-bit Windows, but as far as I know there is no such 32-bit Windows driver.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #2
On Mon, 12 Apr 2004 12:54:17 GMT in comp.lang.c++, al***@start.no (Alf
P. Steinbach) wrote,
C++ provides no such facility. That would be OK, except C++ also actively
sabotages the facility that in practice is universally available, namely
the ASCII carriage return character (ASCII character 13, which is denoted by
'\r' in C++ (but note that '\r' is not necessarily denoted by ASCII 13)).
The sabotage takes the form of possible translation of the carriage return
character, and that this possible translation can not be turned off for
the standard named iostreams, although it can be turned off for other streams.


It is certainly true that C++ allows an implementation to stomp all over
'\r' or for that matter any other character that you might send to a
text output stream (translate from ASCII to EBCDIC, or whatever.)
But, in practice, '\r' seems to be usually left alone and function as
you might hope. '\n' is of course another matter entirely, and '\r' on
input is also questionable. So, I think using '\r' is a better bet than
looking for terminal-defined escape sequences and hoping that the output
stream won't sabotage them. At least I would try it first.

Jul 22 '05 #3
David Harmon writes:
On Mon, 12 Apr 2004 12:54:17 GMT in comp.lang.c++, al***@start.no (Alf
P. Steinbach) wrote,
C++ provides no such facility. That would be OK, except C++ also activelysabotages the facility that in practice is universally available, namely
the ASCII carriage return character (ASCII character 13, which is denoted by'\r' in C++ (but note that '\r' is not necessarily denoted by ASCII 13)).
The sabotage takes the form of possible translation of the carriage returncharacter, and that this possible translation can not be turned off for
the standard named iostreams, although it can be turned off for other
streams.
It is certainly true that C++ allows an implementation to stomp all over
'\r' or for that matter any other character that you might send to a
text output stream (translate from ASCII to EBCDIC, or whatever.)
But, in practice, '\r' seems to be usually left alone and function as
you might hope. '\n' is of course another matter entirely, and '\r' on
input is also questionable. So, I think using '\r' is a better bet than
looking for terminal-defined escape sequences and hoping that the output
stream won't sabotage them. At least I would try it first.


Does the word "sabotaged" mean anything at all to you? You would go through
a hell of a lot of platforms before you found one where CR worked as
intended by the designers of ASCII. My guess is that you would never find
one unless it was in a museum someplace. The OP wants the gotoxy() function
which is probably in conio or ncurses. He should post to a platform
specific newsgroup for further information.
Jul 22 '05 #4
On Mon, 12 Apr 2004 11:55:39 -0700 in comp.lang.c++, "osmium"
<r1********@comcast.net> wrote,
Does the word "sabotaged" mean anything at all to you? You would go through
a hell of a lot of platforms before you found one where CR worked as
intended by the designers of ASCII.
What do you think was intended by the designers of ASCII? What were
their names? Bitch.
My guess is that you would never find
one unless it was in a museum someplace.
I compiled the following program with MS Visual C++ version 6.0.
Of course many would say it belongs in a museum someplace, but in fact
many people still use it.

#include <iostream>
int main()
{
for(int i=0; i<500; i++)
{
std::cout << "\rValue: " << i;
}
}

When I run it, I see "Value: " followed by a number in one place on my
screen that is counting up rapidly to 499. This is exactly what the OP
asked for. Owners of non-museum computers may see only the final
result.

I compiled and ran the same program with the free Digital Mars compiler
http://www.digitalmars.com with exactly the same results.
The OP wants the gotoxy() function
which is probably in conio or ncurses. He should post to a platform
specific newsgroup for further information.


He got the information he asked for. If he wants something beyond that,
a platform specific newsgroup is a good idea.

Jul 22 '05 #5
"David Harmon" <so****@netcom.com> wrote in message
news:40***************@news.west.earthlink.net...
On Mon, 12 Apr 2004 11:55:39 -0700 in comp.lang.c++, "osmium"
<r1********@comcast.net> wrote,
Does the word "sabotaged" mean anything at all to you? You would go
through
a hell of a lot of platforms before you found one where CR worked as
intended by the designers of ASCII.


What do you think was intended by the designers of ASCII? What were
their names? Bitch.
My guess is that you would never find
one unless it was in a museum someplace.


I compiled the following program with MS Visual C++ version 6.0.
Of course many would say it belongs in a museum someplace, but in fact
many people still use it.

#include <iostream>
int main()
{
for(int i=0; i<500; i++)
{
std::cout << "\rValue: " << i;
}
}

When I run it, I see "Value: " followed by a number in one place on my
screen that is counting up rapidly to 499. This is exactly what the OP
asked for. Owners of non-museum computers may see only the final
result.


Although I had to add a Sleep(50); (from <windows.h>) to actually see
anything on this P4 2667MHz, the same result is achieved with Visual C++
..Net 2003.

--
Unforgiven
Jul 22 '05 #6
> The OP wants the gotoxy() function
which is probably in conio or ncurses. He should post to a platform
specific newsgroup for further information.


Sort of. I don't program exclusively on one platform, and I very often
program applications which should run on multiple platforms. In fact
I'm woefully ignorant of non portable libraries, and hope to be able to
remain so. So I am looking for (and asked for) a way to get some
functionality under standard C++ that allows me to keep a running update
of some value (one value at a time is sufficient), so that I don't have
pages and pages of difficult to parse (human eye parse) output.

I often find I would like to be able to do this, so my desire for a
standard compliant method to do this transcends my current project,
which is in any case meant to be compiled with various different
compilers to test for optimization issues. Further, it will have to run
on both windows and linux machines, and in an ideal world, I'd like the
results to be the same if they are running it from a dos shell, cygwin
shell, or linux shell. So I don't think posting to a platform specific
newsgroup would be helpful.

Really, just the ability to work with a single line of output at a time,
being able to back up to a certain point and update the value, instead
of a new line of output every time, would be sufficient for my needs.
The results I'm looking for are like the output for the par2 parity
checker.

The \r thing sounds like a good idea, and I'll try it.
Jul 22 '05 #7

"glen_stark" <st***@ifh.ee.ethz.ch> wrote in message
news:40******@pfaff2.ethz.ch...
The OP wants the gotoxy() function
which is probably in conio or ncurses. He should post to a platform
specific newsgroup for further information.


Sort of. I don't program exclusively on one platform, and I very often
program applications which should run on multiple platforms. In fact
I'm woefully ignorant of non portable libraries, and hope to be able to
remain so. So I am looking for (and asked for) a way to get some
functionality under standard C++ that allows me to keep a running update
of some value (one value at a time is sufficient), so that I don't have
pages and pages of difficult to parse (human eye parse) output.

I often find I would like to be able to do this, so my desire for a
standard compliant method to do this transcends my current project,
which is in any case meant to be compiled with various different
compilers to test for optimization issues. Further, it will have to run
on both windows and linux machines, and in an ideal world, I'd like the
results to be the same if they are running it from a dos shell, cygwin
shell, or linux shell. So I don't think posting to a platform specific
newsgroup would be helpful.

Really, just the ability to work with a single line of output at a time,
being able to back up to a certain point and update the value, instead
of a new line of output every time, would be sufficient for my needs.
The results I'm looking for are like the output for the par2 parity
checker.

The \r thing sounds like a good idea, and I'll try it.


As others have pointed out, there is not standard portable
way to do what you're asking. As for writing 'easy-to-read'
code, factor out this kind of platform-specific stuff into
separate modules, and choose a common name for all such
functions (link to the appropriate one for each target
platform), then your 'main' code will be 'cleaner'.

-Mike


Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.