-
November 4th, 2013, 11:38 AM
#1
Change Output of Console
is there a way to change output of console without clearing the screen? so making some kind of animation?
e.g.
I have used
is there any way I can erase last "lo" and replace it by "p" so I will have "Help" without clearing the screen ? just changing the output like some text file?
I tried using something like this
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "abcd";
long pos = cout.tellp();
cout.seekp(pos-2);
cout.write("ef", 2);
cout.flush();
cin.get();
return 0;
}
but it doesnt work, there is still a "abcd"...
-
November 4th, 2013, 12:18 PM
#2
Re: Change Output of Console
Use the special console API functions.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
You can also try using backspace. The following prints "help"
Code:
int main()
{
cout << "hello" << "\b\b" << "p " << endl;
return 0;
}
The backslash character constants are
\b backspace
\f formfeed
\n newline
\r return
\t horizontal tab
\" double quote
\' single quote
\\ backslash
\v vertcal tab
\a alert
\N octal constant
\xN hexadecimal constant
\? question mark
Last edited by 2kaud; November 4th, 2013 at 01:00 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 4th, 2013, 12:25 PM
#3
Re: Change Output of Console
this will print the help, but it wont print hello and then erase "lo" and replace it by "p", well yeah it does that ,but before it shows up on the screen
-
November 4th, 2013, 01:01 PM
#4
Re: Change Output of Console
Code:
int main()
{
cout << "hello";
Sleep(2000);
cout << "\b\b" << "p ";
return 0;
]
If you need anything more sophisticated you should be looking at the special console functions. I gave the link in post #2.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 4th, 2013, 01:12 PM
#5
Re: Change Output of Console
Originally Posted by 2kaud
Code:
int main()
{
cout << "hello";
Sleep(2000);
cout << "\b\b" << "p ";
return 0;
]
If you need anything more sophisticated you should be looking at the special console functions. I gave the link in post #2.
ty, this one works, I guess mine didnt work since I was using cin.get() to go to the next step and it couldn't delete previous chars since there werent any on that line... :/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|