now at the end of my out put i am putting a carriage return "\r" s that i can gain output on the same line but i am facing a problem...
such that... -
cout<<"My name is Ayan \r";
-
system("pause");
-
cout<<"lalala";
-
this make like this :
lalalae is Ayan
i.e all after "My name" remains in the second output....as if i am gettn a feedback from my previous output....how to tackle this...plez help...
12 1443
now at the end of my out put i am putting a carriage return "\r" s that i can gain output on the same line but i am facing a problem...
such that... -
cout<<"My name is Ayan \r";
-
system("pause");
-
cout<<"lalala";
-
this make like this :
lalalae is Ayan
i.e all after "My name" remains in the second output....as if i am gettn a feedback from my previous output....how to tackle this...plez help...
Yep, nothing told your console to clear the rest of that line so previous output
remains visible. You could do it the quick and dirty way: -
cout<<"My name is Ayan \r";
-
system("pause");
-
cout<<"lalala "; // enough spaces
-
kind regards,
Jos
Yep, nothing told your console to clear the rest of that line so previous output
remains visible. You could do it the quick and dirty way: -
cout<<"My name is Ayan \r";
-
system("pause");
-
cout<<"lalala "; // enough spaces
-
kind regards,
Jos
but this blocks my execution....which i dnt want...i thought of a process of getting the length my previous output and print space through out the output...then print my new output....i know its dirty but do you have any better alternative(s)...
You can use system("cls") to clear the entire screen of output, but not just the previous line. Will this work for you?
You can use system("cls") to clear the entire screen of output, but not just the previous line. Will this work for you?
i already experimented with that...but since its between a never ending loop...only to be ended by a keyboard input... -
-
while(!_kbhit())
-
{
-
-
code...
-
-
}
-
so if i use system("CLS") it takes much CPU time and screen flickers...and its too a OS dependent alternative and nasty one too..
any other better alternatives....
but this blocks my execution....which i dnt want...i thought of a process of getting the length my previous output and print space through out the output...then print my new output....i know its dirty but do you have any better alternative(s)...
I don't understand what you mean by "but this blocks my execution". The little
hack I supplied works identical to what you wrote in your OP; it just prints
enough spaces to erase previous characters on that line. Nothing blocks.
kind regards,
Jos
I don't understand what you mean by "but this blocks my execution". The little
hack I supplied works identical to what you wrote in your OP; it just prints
enough spaces to erase previous characters on that line. Nothing blocks.
kind regards,
Jos
ok let me explain....and its very hard to do so without posting the full code...but i am trying to be as simple as i can -
srand(time(0));
-
-
while(!_kbhit()
-
{
-
cout<<"The random number is :" <<rand()<<" \r";
-
}
-
-
now suppose for the first time the random number generated is 1000
so its prints ...
The random number is :1000
now the next random number be 3 but it will print
The random number is :3000
000 as a feedback from previous output...
now u proposed system(pause);
now if i design the code for minimum user interaction ur proposal defies it....as it will wait for a key press....and as a sideeffect my loop ends...as my loop is also waiting for a key press to terminate...
phewwww...well i think i presented my problem well...
ok let me explain....and its very hard to do so without posting the full code...but i am trying to be as simple as i can -
srand(time(0));
-
-
while(!_kbhit()
-
{
-
cout<<"The random number is :" <<rand()<<" \r";
-
}
-
-
now suppose for the first time the random number generated is 1000
so its prints ...
The random number is :1000
now the next random number be 3 but it will print
The random number is :3000
000 as a feedback from previous output...
now u proposed system(pause);
now if i design the code for minimum user interaction ur proposal defies it....as it will wait for a key press....and as a sideeffect my loop ends...as my loop is also waiting for a key press to terminate...
phewwww...well i think i presented my problem well...
Well, the system("pause") was your idea (see your original article) and I just
copied it. And when I wrote "enough spaces" that didn't imply "exactly enough"
spaces, maybe an additional, say, 50 spaces can do it (if the line lengths don't
differ more than 50 characters).
kind regards,
Jos
Well, the system("pause") was your idea (see your original article) and I just
copied it. And when I wrote "enough spaces" that didn't imply "exactly enough"
spaces, maybe an additional, say, 50 spaces can do it (if the line lengths don't
differ more than 50 characters).
kind regards,
Jos
hmm ....my original post confused you...ok ignore it and think about my last post...and the problem i showcased...
If you know the length of what you are outputing, then you should be able to determine how many spaces (if you want to use the exact number of spaces to clear the rest of the line). However, as Jos said, you could print out a bunch of excess spaces (the maximum you think you would require that would not cause you to move to the next line) to wipe any excess characters.
An alternative to '\r' is to use '\b' a bunch of times to backspace from the end to where you want to start writing. It requires more code and you to know how many characters to backspace over. In certain cases this may be slower or faster, depening on how many backspaces you do compaired with how many characters you would have to print out from the begining of the line. The more characters you output, the slower it will be.
Does this help?
Adrian
If you know the length of what you are outputing, then you should be able to determine how many spaces (if you want to use the exact number of spaces to clear the rest of the line). However, as Jos said, you could print out a bunch of excess spaces (the maximum you think you would require that would not cause you to move to the next line) to wipe any excess characters.
An alternative to '\r' is to use '\b' a bunch of times to backspace from the end to where you want to start writing. It requires more code and you to know how many characters to backspace over. In certain cases this may be slower or faster, depening on how many backspaces you do compaired with how many characters you would have to print out from the begining of the line. The more characters you output, the slower it will be.
Does this help?
Adrian
thnx Adrian about this /b idea sounds good and i will implement that...atleast its a bit better than the "filling up with spaces" technique for my case....
neways thanks to all of you for your coopeartion....i wll post if i face any difficulty regarding this any more....
thnx Adrian about this /b idea sounds good and i will implement that...atleast its a bit better than the "filling up with spaces" technique for my case....
neways thanks to all of you for your coopeartion....i wll post if i face any difficulty regarding this any more....
Not all terminals wipe out a previous character when a '\b' is printed. You still
have to print spaces over the previous output then.
kind regards,
Jos
Not all terminals wipe out a previous character when a '\b' is printed. You still
have to print spaces over the previous output then.
kind regards,
Jos
Yeah, I wasn't meaning that the backspace would delete the character, it just moves the cursor to the left in all of the terminals I have ever used.
Adrian
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fred Bloggs |
last post by:
Hi,
Can anybody help, I would like to prevent a carraige return from submitting
a form, is there a way of doing this using a PHP script?
Cheers,
Sandy, new to PHP
|
by: Robert Oschler |
last post by:
Hello,
I am using the following function to try and strip both carraige returns and
line feeds, ASCII 13 and 10 respectively, from a string. It doesn't seem to
be working:
x = filter(lambda...
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.09.2004
Hello,
I need to implement a library containing a hierarchy of classes
together with some binary operations on objects. To fix attention,
let me assume that it is a...
|
by: Tariq |
last post by:
Hi,
I am trying to do this bit using client side script in an asp page
var x = "<%ServerVar%>";
The issue is if SerVar has carraige returns the Unterminates String
Constant error is thrown...
|
by: Dany |
last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
|
by: Fernando Barsoba |
last post by:
Dear all,
I have been posting about a problem trying to encrypt certain data using
HMAC-SHA1 functions. I posted that my problem was solved, but
unfortunately, I was being overly optimistic. I...
|
by: Jean-François Michaud |
last post by:
Hello people,
I am rather puzzled by this problem I am having with doubles here. The
code seems to execute correctly for awhile and then all a sudden
printfing out my doubles, I get -1.#IND00...
|
by: BlueTorpeedo |
last post by:
Im writing a win32 C++ MFC console app that uses the CMimeMessage Class.
I read text from a file, character by character, into a CString. I then put the CString into the email body via the addtext()...
|
by: Fred |
last post by:
Hello,
I am having a problem with a multiline string that I create from a byte
array (xml file). I am using StringBuilder and Ecoding the string to ASCII
(code below).
/ Upload the...
|
by: Light |
last post by:
Hi all,
I posted this question in the sqlserver.newusers group but I am not getting
any response there so I am going to try it on the fine folks here:).
I inherited some legacy ASP codes in my...
|
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: 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$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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,...
|
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...
| |