Limiting amount of text shown in console box

This is a discussion on Limiting amount of text shown in console box within the C++ Programming forums, part of the General Programming Boards category; Ok the program I am making, at points, shows A LOT of text on screen. Instead of changing the size ...

  1. #1
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60

    Limiting amount of text shown in console box

    Ok the program I am making, at points, shows A LOT of text on screen. Instead of changing the size of the console box, I would just like to limit the amount of text that appears. After so much appears, the user would have to press a key to continue. I wasnt sure on how to do this.

    Most of the thigns Ive read about, they describe how to get/change the size of the console box. I never really saw how to limit the amount of text.

    Does anyone know how to do this?
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  2. #2
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    ---------------Sorry if me double posting on this makes anyone mad-----------------------


    Ok, I'm double posting because I think I may have found something, but im not sure. I found this function called getch(). I'm not positive on how it works, but I think I know how.

    Ok I found out abotu a function called getch(). So I made a little program(shown below) to see how it works. After running the program below...once I get passed the numbers the "Press either F or G" shows up but you dont have time to read it. I take it im using getch() wrong?

    Code:
    #include <iostream>
    #include <conio.h>
    
    using namespace std;
    
    int main()
    {
        string fg;
        
        
        cout << "1\n";
        cout << "2\n";
        cout << "3\n";
        cout << "4\n";
        cout << "5\n";
        cout << "6\n";
        cout << "7\n";
        cout << "8\n";
        getch();
        cout << "9\n";
        cout << "10\n";
        cout << "11\n";
        cout << "12\n";
        cout << "13\n";
        cout << "14\n";
        cout << " Press either F or G now.\n\n\n";
    
        if (fg == "F" || fg == "f")
        {
               cout << "YEAH!\n";
               getch();
               }
        else if (fg == "G" || fg == "g")
        {
             cout << "Press enter to exit..BECAUSE YOU FAILED!";
             getch();
        }
    }
    Last edited by FingerPrint; 03-29-2006 at 10:24 PM.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    don't use getch(), just use cin.get()

    getch() is non-standard code, and cin.get() is standard. cin.get() will only accept enter though, wereas getch() works on most keys.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    So if I did something like:

    Code:
    int main()
    {
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cin.get();
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    }
    Would that show the first set of text until ENTER was pressed. Then when enter is press it shows the rest?
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    yess
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Oh hey thanks man...got it working now.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  7. #7
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Well actually that didnt really solve my problem. I mean it helped a bit. I got off track there for a minute.

    That helps me to stop text from being shown until a person hits ENTER, but I was looking for a way to show 25 lines of text. Then when the user presses ENTER, all that goes away and the next 25 lines appear.

    Or do I just have to place the cin.get() correctly to get taht result?
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    well, getch() wont' do that, and there is no standard way to do that... at your level, you're probably best off using a system() call:
    Code:
    windows: system("cls");
    linux: system("clear");
    note that this opens up a security hole in your program though, and you'll want to stop using system() as soon as you can.

    to use system you should include <cstdlib>
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Do you think you could give me a small example of what that would look like?

    Usually when I search for things I find things that are text only, without anye examples...and its kind of hard to learn how to do something when there isnt an example.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Code:
    int main()
    {
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cin.get();
    system("cls");  //I'm assuming you're using windows
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    cout << "text\n";
    }
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Could you not use an int and every time you add a new line you increment it by 1 intil it is 25...then ytou clear the screen and continue

  12. #12
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I suppose... you could... but that'd probably be more code than you need, unless your output is in some kind of loop... or you absolutely needed to keep track of every 25 lines...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Wow...for once I didn't get told that wouldnt work!

    Yay!

  14. #14
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    I asked for an example because I thought it would be harder than that, lol.

    Thanks man.
    Code:
    /* ------------------------------------------------------------------*/
                               // INSERT CODE HERE
    /* ------------------------------------------------------------------*/

  15. #15
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    I'll paraphrase and add to what was suggested.

    Every time you output a NEWLINE:
    -- increment a counter
    -- test the counter
    -- if counter is >= your max lines
    ---- zero the counter
    ---- cin.get()

    This can be all done in a function, such as:
    line = pauseOutput(line);

    The function accepts the current number of lines, returns the updated number of lines.

    As for system() calls, avoid them. You don't need to clear the screen...


    So FingerPrint, you like my sig, eh?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting a text box value into a character array?
    By n00bguy in forum Windows Programming
    Replies: 3
    Last Post: 07-29-2006, 08:08 PM
  2. edit box affecting displaying of text?
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2005, 03:28 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  4. Adding text to a disabled edit box
    By osal in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 01:23 PM
  5. String from a text box
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 09-16-2001, 03:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21