Change Output of Console
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Change Output of Console

  1. #1
    Join Date
    Oct 2013
    Posts
    39

    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

    Code:
    cout << "Hello";
    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"...

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,848

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Oct 2013
    Posts
    39

    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

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,848

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    Join Date
    Oct 2013
    Posts
    39

    Re: Change Output of Console

    Quote Originally Posted by 2kaud View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center