improving input (replacing "cin")

This is a discussion on improving input (replacing "cin") within the C++ Programming forums, part of the General Programming Boards category; is there a way to input values without having to use "Enter"? I've heard of getch and cin.get but don't ...

  1. #1
    Unregistered
    Guest

    improving input (replacing "cin")

    is there a way to input values without having to use "Enter"?
    I've heard of getch and cin.get but don't know how to use them. Any advice?

    for example, how can I replace the cin with getch or cin.get?

    <code>

    int array[10], x;
    for(x=0;x<10;x++)
    {
    cin>>array[x];
    //do I do something like cin.get(array[x]); or something?
    }

    </code>

    also, what is the ASCII code for Backspace, if there is any.

  2. #2
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    #include conio.h
    char KeyInput = getch();

    //at least i think its conio.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  3. #3
    Unregistered
    Guest
    correction in code:

    for(x=0;x<9;x++) //forgot that it begins at array[0]

  4. #4
    31173 h4x0r gnu-ehacks's Avatar
    Join Date
    Nov 2001
    Posts
    556
    Yeah, you should use getch();. That is better, and it doesn't return the input on the screen unless you print it manually, which is usually a good thing.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    even better...

    check if the keyboard buffer has something, and if so, return the scan code and ascii in a short int... [16 bits of space...] else return zero... this way, you get to do other things if no input occurs, since you don't have to wait... plus you get scan and ascii codes so you can do special keyboard presses which aren't mapped in ascii... the scan codes let you use the keyboard's keys more like buttons rather than assigned keys...
    hasafraggin shizigishin oppashigger...

  6. #6
    Unregistered
    Guest
    there seems to be a problem with the following code. when I input the values, the values don't get show up until the loop terminates. why is that? is there a solution to correct this?

    also, how do I change the array to a pointer? when I use "int *array", an error occurs when the loop executes.

    <code>
    //using MSVC++ 6.0
    #include<iostream.h>
    #include<conio.h>
    int main()
    {

    int
    array[10], //seems like getch() only works with int types
    x;
    for(x=0;x<9;x++)
    {
    array[x] = getch();
    cout<<array[x]<<",";
    }

    while(getch())
    {return 0;}
    }
    </code>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 02:59 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 12:09 PM
  4. Replacing tabs in the input
    By dineren in forum C Programming
    Replies: 1
    Last Post: 08-22-2003, 06:00 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM

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