Thread: i don't want number on output

  1. #1
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105

    i don't want number on output

    Code:
    if(keydown(VK_NUMPAD4))
    {	
        while(keydown(VK_NUMPAD4))
            Sleep(1);	
    
        cout << "set scroll number: ";			
        cin >> scroll_num;
           
        return;
    }
    When the user presses 4 to enter this section the number 4 is outputed, so the user has to press backspace before entering their input. I want it so there is nothing there.

    The user sees somthing like this when pressing 4....

    set scroll number: 4

    when it should be...

    set scroll number:

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I think the best you can do is simulate the backspace key by sending the appropriate events to the application.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    22
    Just to see if I understand correctly, you want them to press the number 4 and on immediately pressing the number you don't want the number to appear on the input line?

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    You could always use getch:

    Code:
    char ch=getch();
    
    if ( ch == '4' ) {
      std::cout<< "Set scroll value: ";
      std::cin >> scroll_num;
    }
    #include <conio.h> but it's not standardised, alas.

  5. #5
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105

    thx twomers

    yea that works, thanks.

  6. #6
    Registered User
    Join Date
    Sep 2007
    Posts
    22
    twomers, getch() seems quite useful, do you know any references with more information on the conio library?

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    First of all, you should be aware that the functions in conio.h are not very portable. conio.h was originally a Borland-specific header file that Dev-C++ implemented for some strange reason.

    Secondly, some of the functions in Borland's original conio.h are not available in Dev-C++'s conio.h: http://www14.brinkster.com/aditsu/de...faq.html#conio

    Using Windows functions as outlined in adrianxw's tutorials might be more portable than using conio.h functions: http://www.adrianxw.dk/SoftwareSite/index.html
    At least with Windows functions you could compile your code with other Windows compilers like MSVC.

    As for some of the functions in conio.h -- you could try the Wikipedia entry: http://en.wikipedia.org/wiki/Conio.h
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Bad output -- possible input buffer problems
    By jake123 in forum C Programming
    Replies: 8
    Last Post: 02-18-2008, 03:36 PM
  3. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  4. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  5. I am lost on how to read from file and output to file?
    By vicvic2477 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2005, 11:52 AM