Thread: dynamic output; changing without reprinting

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    31

    Post dynamic output; changing without reprinting

    My question is regarding what I call "dynamic output". That is to say, printed characters that are able to change without reprinting. A few examples might help:

    When downloading a file, such as with wget, the printed text changes while remaining 'static'. The progress bar on wget fills up as the file downloads. The printed percentage (eg 75%) also changes as the download progresses. This is done without the console reprinting the entire paragraph every time the percentage increases--this is what I mean by "dynamic".

    I have been able to find no resources on this, most likely because I don't even have an idea of what it's really called. What I would like to know is: firstly, what this is called; secondly, optionally, links or suggestions for resources on this topic.

    I would describe my knowledge of C++ as basic. If you are expected to be able to figure this out on your own with the use of classes, pointers and simpler things, I have come up quite dry. If it requires a greatly more advanced knowledge of C++, I would still appreciate knowing what it is called.

    Thanks!

  2. #2
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    There is no standard way. Ncurses is the most common library for terminal manipulation.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You may want to state the OS for which you are going to program. Since there's no standard C++ way, you may be forced to use some OS API for this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    The simplest way is with the carriage return on *nix and Windows. Don't know exactly if that's exactly how wget does the progress bar, but it seems like it after a quick check.

    Code:
    #include <iostream>
    
    int main()
    {
        for(unsigned times = 1; times; ++times)
        {
            if((times % 1111) == 0)
            {
                std::cout << "\rI've looped " << times << " times";
            }
        }
        std::cout << "Now, onto more useful work";
    }
    It works as long as what you print stays the same length or gets bigger. If it gets smaller, you have to be a bit smarter to erase the characters left from the longer output.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    31
    Quote Originally Posted by Elysia View Post
    You may want to state the OS for which you are going to program. Since there's no standard C++ way, you may be forced to use some OS API for this.
    I am programming on/for Linux.

  6. #6
    Registered User
    Join Date
    Mar 2008
    Location
    Coimbra, Portugal
    Posts
    85
    Quote Originally Posted by frog View Post
    I am programming on/for Linux.
    Then, for starters, if none of the advice in here works, you should

    Code:
    man 3 ncurses

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  2. strange virtual function output
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2008, 08:08 AM
  3. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 06:41 PM
  4. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM
  5. Changing Output
    By Jripeus in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2002, 06:16 PM

Tags for this Thread