Hi all,
I am doing my assignment and have a question ,how can I clear the standard
output(screen)?
following is the fake code:
=============== =============== =======
main(){
for loop(int i++){
printf (" %d",i);
}
}
=============== =============== ======
the problem is,I want to clean the previous output number and then print
only the new number .So it is like a on-screen counter somehow.
Thanks a lot guys!!! 5 9586
"Joseph" <wu*******@hotm ail.com> wrote in message
news:Xn******** *************** @203.96.216.21. .. Hi all,
I am doing my assignment and have a question ,how can I clear the standard output(screen)?
following is the fake code:
=============== =============== =======
main(){
for loop(int i++){
printf (" %d",i);
}
} =============== =============== ======
the problem is,I want to clean the previous output number and then print only the new number .So it is like a on-screen counter somehow.
This sounds pretty similar to a FAQ. See the FAQ
( http://www.parashift.com/c++-faq-lite/), section 15 ("Input/output via
<iostream> and <cstdio>"), question 20 ("How can I clear the screen? Is
there something like clrscr()?").
There are some (non-portable) ways to do what you want. For instance, on
Windows, using VS.NET2003, the following code displays a counter that is
periodically overwritten:
#include <stdio.h>
int main() {
int i = 10;
printf("Counter : %d", i);
for ( int i = 11; i < 20; ++i ) {
// Use a "hack" that uses backspace to erase the number
printf( "\b\b" );
printf( "%d", i );
// Do something to pause here, like Sleep()
for (int j = 0; j < 100000000; ++j ){}
}
printf("\n");
return 0;
}
--
David Hilsee
The most portable way is:
system("cls");
HTH,
Gernot
Gernot Frisch wrote: The most portable way is: system("cls");
HTH, Gernot
bash: cls: command not found
--
perl -e 'printf "%silto%c%sal%c %s%ccodegurus%c org%c", "ma", 58, "mw",
107, 'er', 64, 46, 10;'
Joseph wrote: ... I am doing my assignment and have a question ,how can I clear the
standard output(screen)?
following is the fake code:
=============== =============== =======
main(){
for loop(int i++){
printf (" %d",i);
}
} =============== =============== ======
the problem is,I want to clean the previous output number and then print only the new number .So it is like a on-screen counter somehow. ...
Instead of clearing the entire screen you might want to try to print
every new number at the same place where the previous one was printed
(thus overwriting the previous one) by doing it like this
printf("%d\r", i);
I don't think it is 100% portable in theory, but in practice this will
work on many platforms.
--
Best regards,
Andrey Tarasevich
Joseph <wu*******@hotm ail.com> writes: Hi all,
I am doing my assignment and have a question ,how can I clear the standard output(screen)?
following is the fake code:
[...]
the problem is,I want to clean the previous output number and then print only the new number .So it is like a on-screen counter somehow.
One way is to print out a lot of blank lines, so the old output will
disapaire, another way is using the preprozessor:
//do this in a seperate header file
#if defined LINUX
#define CLEAR_SCREEN clear
#elif defined WIN32
#define CLEAR_SCREEN cls
//for more platforms
#endif
or just spliting it into a front and a back end, by using in the backend
the platform specfic functions or libraries.
On Linux for example ncurouses and on windows for example the code that
David posted.
HTH && kind regards,
Nicolas
--
| Nicolas Pavlidis | Elvis Presly: |\ |__ |
| Student of SE & KM | "Into the goto" | \|__| |
| pa****@sbox.tug raz.at | ICQ #320057056 | |
|-------------------University of Technology, Graz----------------| This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Newgene |
last post by:
Hi, group,
May I ask a newbie question?
Given the below example:
for i in range(100):
print "%s%%" % i
I want to show the progress by print 1% to 100%. But I hope each
output will clear the previous output before print, so that I can see a
|
by: Leon |
last post by:
"stdout" is file object, it open mode is "w"
and it have a close() fuction.....
while it run close(), how to reopen it
because I want to do rewrite it
stdout content update
|
by: Alexander Stippler |
last post by:
Hi,
The short story: I have to redirect stdout (not cout!!) to an ostream.
How can I manage this?
The long story:
I use the NAGC numerics library with C++ and want to use its output
routines for e.g. complex matrices. The problem: You can either print
to a file (given by filename) or to stdout. To call the NAGC-method
within an operator<< thus I have to redirect stdout to the given
|
by: ritchie |
last post by:
Hi,
I am trying to clear the screen in my program.
I am loking for something that will work on all compilers, especially
Borland & MS Visual Studio 6.
On Visual studio I used 'system("cls");' and this works fine but this
won't work for Borland.
On Borland I used 'clrscr() ' function and it worked ok, but not for
Visual Studio.
|
by: boss_bhat |
last post by:
Assume stdout is closed and if i now
want to open stdout, how to open it?
IS this correct way of opening stdout
fopen(stdout,"/dev/null");
Thanks
Prasanna Bhat Mavinkuli
| |
by: Luigi |
last post by:
Hi to all!
I'd like to execute an external program capturing the stdout/stderr
messages at "real-time". I mean that I don't want to wait for the end
of the process. If I write a code like this:
import os
import sys
class Runner:
|
by: David Mathog |
last post by:
A program of mine writes to a tape unit. Output can be either through
stdout or through a file opened with fopen(). When all the data is
transferred to tape the program needs to close the output stream so that
the tape driver will write a filemark on the tape. Otherwise multiple
clumps of data saved to tape would all appear to be one big file on the
tape.
When the tape unit device was explicitly opened with fopen()
that's possible:...
|
by: MisterPete |
last post by:
How can I inherit from file but stil create an instance that writes to
stdout?
-----------
I'm writing a file-like object that has verbosity options (among
some other things). I know I could just set self.file to a file object
rather than inheriting from file. I started with something like this
(simplified for clarity):
class Output(object):
def __init__(self, file=sys.stdout, verbosity=1):
|
by: Dinsdale |
last post by:
I am writing a small console application that runs fine unless I am re-
directing the output to a file (i.e. c:\ app.exe >>output.txt) . I
have determined that the issue is caused by the Console.Clear()
function. When piping to a file, the console.clear causes the
following error:
Unhandled Exception: System.IO.IOException: The handle is invalid.
at System.IO.IO__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
|
by: =?ISO-8859-1?Q?Richard_Sim=F5es?= |
last post by:
Hopefully, this explanation will sufficiently clear despite the lack
of code.
I wrote a python script that takes data via stdin, does stuff with the
data, and outputs the result to stdout. A friend wrote a perl script
that opens a pipe to my script, feeds it data, and then accepts the
result. The problem here is that the python script's outputting the
result to stdout via print statements isn't doing what we expected: my
friend's perl...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |