Help with getch();

This is a discussion on Help with getch(); within the C++ Programming forums, part of the General Programming Boards category; Why does getch(); have to get the character before it will output the cout<< before it??? void displayalbum(NODE* &head,apstring &album) ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    22

    Help with getch();

    Why does getch(); have to get the character before it will output the cout<< before it???

    void displayalbum(NODE* &head,apstring &album)
    {
    NODE *node=head;
    int count=0;

    cout<<"\n";

    for(node;node;node=node->next)
    {
    if(node->album==album)
    {
    cout<<node->artist<<endl;
    cout<<" "<<node->album<<endl<<" Loaned : "<<node->loaned<<endl;

    if(node->loaned=="y")
    {
    cout<<" To : "<<node->towho<<endl;
    }

    cout<<"\n";

    count++;
    }
    }

    if(count==0)
    cout<<"* CD NOT FOUND *\n\n";

    cout<<"Press any key to continue.";
    getch();

    cout<<"\n";

    return;

    }
    <^>( * ; * )<^>

  2. #2
    Satan valar_king's Avatar
    Join Date
    Aug 2001
    Posts
    288
    try using _getch()
    -Save the whales. Collect the whole set.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    22
    I tried using _getch(); but it gave me the same problem... any more suggestions???
    <^>( * ; * )<^>

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    The problem you are having is because cout is buffered....

    cout<<'\n'; // this does not flush the buffer.

    cout<<endl; // this on the other hand will.

    to flush specifically without using a newline ....

    cout<<"Are you starting to get it??"<<flush;

    cout will also be flushed on any call to cin (providing you have not untied the streams).
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    Try
    [/CODE]

    cout<<"Press any key to continue.Test" << endl << flush ;
    getch();
    [CODE]

    I think you just need to force (flush) the output.

    dang

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    22
    Thanks, that fixed the problem...
    <^>( * ; * )<^>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  2. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 05:15 AM
  3. Pause a C program without getch()
    By swgh in forum C Programming
    Replies: 4
    Last Post: 02-20-2006, 11:24 AM
  4. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2003, 12:04 AM
  5. Problems with getch()
    By GrNxxDaY in forum C++ Programming
    Replies: 14
    Last Post: 08-12-2002, 03:11 AM

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