473,387 Members | 1,700 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,387 software developers and data experts.

Updating Text on Screen

I have a program that is going to return position data several times a
second. Instead of printing this data to the screen on new line every
time, I would like to simply have the program print "Position: XX" on
one line, adn then update the XX every time there is new data.

I am working with just a simple console app in Linux.

Someone had mention fstream and seekp but I was wondering if anyone had
a bit more guidance or somewhere to look, perhaps a good primer on
using fstream with the screen buffer (almost everything about fstream
that I found relates to using it with a file).

Thanks

Jun 13 '06 #1
8 2960
gt*****@gmail.com wrote:
I have a program that is going to return position data several times a
second. Instead of printing this data to the screen on new line every
time, I would like to simply have the program print "Position: XX" on
one line, adn then update the XX every time there is new data.
Outputting

std::cout << "\rPosition: " << yourpositionvariable;

inside your loop will probably do what you want. Don't forget to finish
the overall output with a single newline.
I am working with just a simple console app in Linux.
Then you might want to post to 'comp.os.linux.development.apps'.
Someone had mention fstream and seekp but I was wondering if anyone
had a bit more guidance or somewhere to look, perhaps a good primer on
using fstream with the screen buffer (almost everything about fstream
that I found relates to using it with a file).


There are several books on standard library available, all decent. One
deals especially with streams, the authors are Kuehl and Langer. I'm not
sure whether your implementation of standard output linked to the screen
(console) is capable of positioning (and what effect it's going to have),
you would need to ask in the newsgroup dedicated to your implementation
or library (or OS).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 13 '06 #2
gtpilot wrote:
I have a program that is going to return position data several times a
second.


Google 'ncurses'.

Then Google for the best forum for these questions. This newsgroup is only
qualified to discuss raw C++, which has no text-positioning facilities.

--
Phlip
Jun 13 '06 #3
Victor Bazarov wrote:
gt*****@gmail.com wrote:
I have a program that is going to return position data several times a
second. Instead of printing this data to the screen on new line every
time, I would like to simply have the program print "Position: XX" on
one line, adn then update the XX every time there is new data.


Outputting

std::cout << "\rPosition: " << yourpositionvariable;

inside your loop will probably do what you want.


The stream should be flushed at the end. Otherwise, the update is probably
done too late:

std::cout << "\rPosition: " << yourpositionvariable << std::flush;

Jun 13 '06 #4
Rolf Magnus wrote:
Victor Bazarov wrote:
gt*****@gmail.com wrote:
I have a program that is going to return position data several
times a second. Instead of printing this data to the screen on new
line every time, I would like to simply have the program print
"Position: XX" on one line, adn then update the XX every time there
is new data.


Outputting

std::cout << "\rPosition: " << yourpositionvariable;

inside your loop will probably do what you want.


The stream should be flushed at the end. Otherwise, the update is
probably done too late:

std::cout << "\rPosition: " << yourpositionvariable << std::flush;


There is no guarantee that \r does what the OP needs, but if it does,
it most likely will do it without flush (IME, anyway).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 13 '06 #5
Victor Bazarov wrote:
Rolf Magnus wrote:
Victor Bazarov wrote:
gt*****@gmail.com wrote:
I have a program that is going to return position data several
times a second. Instead of printing this data to the screen on new
line every time, I would like to simply have the program print
"Position: XX" on one line, adn then update the XX every time there
is new data.

Outputting

std::cout << "\rPosition: " << yourpositionvariable;

inside your loop will probably do what you want.


The stream should be flushed at the end. Otherwise, the update is
probably done too late:

std::cout << "\rPosition: " << yourpositionvariable << std::flush;


There is no guarantee that \r does what the OP needs, but if it does,
it most likely will do it without flush (IME, anyway).


I have no idea if \r usually flushes the stream, but if it does, it will do
it before the line gets written, not afterwards. This might not be very
relevant if you print the line "several times a second", but I would add
the flush anyway.

Jun 13 '06 #6
Won't all of these just print out

Your Position: X1
Your Position: X2
Your Position: X3
Your Position: X4
..
..
..

etc all the way to Xreally big number?

I just want the program to print 1 line to the console during the
entire program, and then go back and basically place the cursor where
the numbers start and write the current value.

Someone suggested using \b to backspace, but that ends up adding some
really wierd cursus images and flickering.

Rolf Magnus wrote:
Victor Bazarov wrote:
Rolf Magnus wrote:
Victor Bazarov wrote:

gt*****@gmail.com wrote:
> I have a program that is going to return position data several
> times a second. Instead of printing this data to the screen on new
> line every time, I would like to simply have the program print
> "Position: XX" on one line, adn then update the XX every time there
> is new data.

Outputting

std::cout << "\rPosition: " << yourpositionvariable;

inside your loop will probably do what you want.

The stream should be flushed at the end. Otherwise, the update is
probably done too late:

std::cout << "\rPosition: " << yourpositionvariable << std::flush;


There is no guarantee that \r does what the OP needs, but if it does,
it most likely will do it without flush (IME, anyway).


I have no idea if \r usually flushes the stream, but if it does, it will do
it before the line gets written, not afterwards. This might not be very
relevant if you print the line "several times a second", but I would add
the flush anyway.


Jun 13 '06 #7
gt*****@gmail.com wrote:
Won't all of these just print out

Your Position: X1
Your Position: X2
Your Position: X3
Your Position: X4
.
.
.

etc all the way to Xreally big number?
(a) Don't top-post.
(b) Why don't you simply try and see instead of asking?
I just want the program to print 1 line to the console during the
entire program, and then go back and basically place the cursor where
the numbers start and write the current value.
You don't have to repeat yourself. We get it. You need the program to
print everything on one line. Go try outputting \r and see what happens.
Someone suggested using \b to backspace, but that ends up adding some
really wierd cursus images and flickering.
Yes, and it's possible that \r will not do what you want. There is no
sure way in *Standard* C++ to do what you want. That's why you were
given the advice to look into 'ncurses' library.

Meanwhile try this:

#include <iostream>

int main() {
for (int i = 0; i < 1000000; ++i)
std::cout << "\rValue = " << i;
std::cout << std::endl;
}

What do you see?
[..]


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 13 '06 #8
> (a) Don't top-post.

My mistake, didn't know it made any difference
(b) Why don't you simply try and see instead of asking?


Again my mistake, I must have misunderstood something along the line.
Yes that \r works for my purposes, and I may uses ncurses i in the long
run.

Thanks for your help

Jun 14 '06 #9

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

Similar topics

0
by: Bob Kaku | last post by:
I'm trying to create a text editing and updating capability to help someone who wants to maintain content on a web page without having to know any HTML or use a web authoring tool and FTP'ng the...
2
by: BG | last post by:
We're having trouble writing the code to update a UI control (label.Text) from a secondary thread. We're using C# with Windows Forms. We have a main form named MainForm, a splash screen form...
7
by: trint | last post by:
I have a textbox (textBox7) that isn't updating.. Is there a way, after I type new text in it, to have it update? It seems to be fairly normal: public class Form1 : System.Windows.Forms.Form {...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
1
by: batista | last post by:
Hello all, I have a third praty grid control...named C1grid. Im using it in one of my apps.. Now, I have bind this grid to a custom dataset class named "DataViewEx". The code of the class is...
2
by: =?Utf-8?B?ZG1idXNv?= | last post by:
I am filling a richtextbox via the AppendText method and it works great. However, I would like to to off screen updating, add my 50 or so lines to the richtextbox, and then turn screen updating...
6
by: =?Utf-8?B?S2Fp?= | last post by:
Hi all, using AJAX Toolkit with vb.net 2.0 how could I make this "Updating..." Screen like e.g. on Codeplex when you click on the "Vote" button...
4
by: directory | last post by:
hey guys, I've got a weird one for ya....i have a form which takes user input in the form of textbox's etc. It then grabs some details from a file and updates some of the labels with some info...
4
by: Edwin Velez | last post by:
http://msdn.microsoft.com/en-us/library/806sc8c5.aspx The URL above gives sample code for use within a Console Application. What I would like to do is use this code within a Windows Form. That...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.