Hi,
I want to control the output such that it always print at the same
line, erasing the line just printed (or erasing a particular posistion at a
certain line). Say, for a simple program like this,
#include <StdAfx.h>
#include <iostream.h>
void main() {
cout<<"Hello World"<<endl;
cout<<":) " <<endl;
}
instead for printing
Hello World
:)
it only print
Hello :) 8 8255
Toro wrote: Hi, I want to control the output such that it always print at the same line, erasing the line just printed (or erasing a particular posistion at a certain line). Say, for a simple program like this,
#include <StdAfx.h>
Non-standard header. You can compile your code without it using your
compiler, but how to do it is off topic in this group. ( Don't get too
stuck with this issue, just understand that it is a non-standard header,
and your code will be fine without it also. )
#include <iostream.h>
#include <iostream>
void main() {
int main()
cout<<"Hello World"<<endl; cout<<":) " <<endl;
std::cout << "Hello World";
std::cout << "\rHello :)" << std::endl;
return 0;
}
Return 0 is not required by the standard, but your compiler might give
an warning if you don't use it.
I'm not sure will \r work similary on all platforms, but AFAIK that is
the best you can do using standard C++.
Aggro wrote: int main()
cout<<"Hello World"<<endl; cout<<":) " <<endl;
std::cout << "Hello World"; std::cout << "\rHello :)" << std::endl;
Why not just
cout << "Hello World";
// erase 5 characters
cout << "\b\b\b\b\b";
Aggro wrote: Toro wrote:
Hi, I want to control the output such that it always print at the same line, erasing the line just printed (or erasing a particular posistion at a certain line). Say, for a simple program like this,
#include <StdAfx.h>
Non-standard header. You can compile your code without it using your compiler, but how to do it is off topic in this group. ( Don't get too stuck with this issue, just understand that it is a non-standard header, and your code will be fine without it also. )
#include <iostream.h>
#include <iostream>
void main() {
int main()
cout<<"Hello World"<<endl; cout<<":) " <<endl;
std::cout << "Hello World"; std::cout << "\rHello :)" << std::endl;
return 0;
}
Return 0 is not required by the standard, but your compiler might give an warning if you don't use it.
I'm not sure will \r work similary on all platforms, but AFAIK that is the best you can do using standard C++.
ain't that \n instead of \r ?
\n = new line
\r = return to the beginning of current line
na ?
for
std::cout << "Hello World";
std::cout << "\rHello :)"<< std::endl;
the output,
Hello :)rld
std::cout << "Hello World";
std::cout << "\rHello :)";
the output
Hello :)
I need to include <iostream.h> and <iostream> if I have cout inside the
program.
I do need <stdfax.h> to have the program compiled without error.
cout<<"Hello World";
cout<<"\b\b\b\b\b";
cout<<":)";
the output is ok but I wonder how I can erase the whole line. (or changed
from something like " it is fun " to "it isn't fun" )
Toro wrote: I need to include <iostream.h> and <iostream> if I have cout inside the program.
No. You only need <iostream>. iostream.h is an old header
with roughly the same content, that shouldnt be used anymore.
cout is now in the namespace std. So you must write
using std::cout;
cout << "Hello World";
or write
std::cout << "Hello World";
I do need <stdfax.h> to have the program compiled without error.
No, you dont *need* this header. It is special header for MS
Compilers that is used for decreasing compile times. You can
compile your code without it.
cout<<"Hello World"; cout<<"\b\b\b\b\b"; cout<<":)";
the output is ok but I wonder how I can erase the whole line. (or changed from something like " it is fun " to "it isn't fun" )
Why don't you try a different approach?
Store the current line in a string and modify it before output.
std::string current_line = "Hello World";
cout << current_line;
current_line = "Hello :)";
std::cout "\r" << current_line;
Or you could only count the number of characters in your
output and later print "\b" to delete the whole output.
hth
Christoph
Toro wrote: Hi, I want to control the output such that it always print at the same line, erasing the line just printed (or erasing a particular posistion at a certain line). Say, for a simple program like this,
There is no way to do this portably, using standard C++. One reason for
this is quite simple - you have no way of knowing that the device
std::cout is "attached to" has this capability. It could be a file, for
example, or a socket, or a printer.
If you want to do this, you should look for some method provided by your
implementation and direct any questions about it to a group that
discusses your implementation. #include <StdAfx.h>
Please don't post non-standard code here. This group is for discussion
of standard C++. In order to help, we often need to be able to copy &
paste your code into our (standard) compilers, and this won't be accepted.
#include <iostream.h>
That's an old pre-standard header. Use <iostream> instead.
void main() {
main returns int in C++. Always has, always will.
cout<<"Hello World"<<endl; cout<<":) " <<endl; }
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Le Géant Vert wrote: Aggro wrote:
Toro wrote:
Hi, I want to control the output such that it always print at the same line, erasing the line just printed (or erasing a particular posistion at a certain line). Say, for a simple program like this,
#include <StdAfx.h> Non-standard header. You can compile your code without it using your compiler, but how to do it is off topic in this group. ( Don't get too stuck with this issue, just understand that it is a non-standard header, and your code will be fine without it also. )
#include <iostream.h> #include <iostream>
void main() { int main()
cout<<"Hello World"<<endl; cout<<":) " <<endl; std::cout << "Hello World"; std::cout << "\rHello :)" << std::endl;
return 0;
} Return 0 is not required by the standard, but your compiler might give an warning if you don't use it.
I'm not sure will \r work similary on all platforms, but AFAIK that is the best you can do using standard C++.
ain't that \n instead of \r ? \n = new line \r = return to the beginning of current line na ?
No. Some platforms will translate the '\r' escape sequence into '\r\n'.
There is no standard process for satisfying the OP's requirements.
Platform specific functions are necessary, and will be discussed in
other newsgroups.
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book http://www.sgi.com/tech/stl -- Standard Template Library This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: qazmlp |
last post by:
I hope comp.lang.c will not find the following question as a
complete off-topic.
I would like to remove ie.comment out the 'cout' statements during
compilation(actually preprocessing) time.
...
|
by: Alex Vinokur |
last post by:
Hi,
Where has output-to-cout gone in the program below?
Thanks,
========= C++ code : File foo.cpp : BEGIN =========
#include <cstdio>
#include <cassert>
#include <iostream>
|
by: mrDumbass |
last post by:
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;
/*
i would like to keep the numbers of the output : Power , step etc,
on the same place...
|
by: Generic Usenet Account |
last post by:
What exactly is the difference between the hex manipulator and the
following statement: cout.setf(ios_base::hex)?
According to Stroustrup, Third Edition, Section 21.4.4, "once set, a
base is...
|
by: olson_ord |
last post by:
Hi,
I am not so new to C++, but I have not used it much. I was trying to
append a string at the end of a previous string. If I just do this in a
test program that is 3 lines long i.e. define the...
|
by: Podrzut_z_Laweczki |
last post by:
Hello, I have question (or 2 :)). Is that true that for a large data
using scanf/printf instead of cin/cout makes that the program runs
faster? And if it is, is it legal to mix scanf/printf with...
|
by: Cliff Martin |
last post by:
Hi,
I am writing a simple filter type program that can take input from
file or stdin, and output to a file or stdout. It would make life much
easier if I could assign cin to a ifstream object...
|
by: shk253 |
last post by:
Hi all - I'm trying to generate a payroll. I'm having trouble with the cout statements overwriting the previous inputs, e.g. enter info for employe 1: blah blah blah. Enter info for employee 2: blah...
|
by: thomas |
last post by:
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<string>
#include<algorithm>
using namespace std;
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |