Thread: Asterisked input

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    Asterisked input

    When you get input throught the cmd, using cin>>, how can I get the input to be all asterisks instead of the actual letters being typed?

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    42
    If you mean a password-like effect, I know that you can use getch() in a loop and output '*' through cout every time.

    #edit: getch() is from conio.h. But it may or may not work depending on the compiler.
    Last edited by Vorok; 06-09-2003 at 03:51 PM.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    There isn't any standard way to do this. getch() is your best bet, but otherwise, you probably need a GUI which you can control.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    34
    I think that there may be a bit mask function that you can use.

    Not quite sure you may want to look into this.

  5. #5
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

  6. #6
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    You may also want to try these various methods of limiting what the user inputs ( ex. number of characters, or the validation character ) :

    Code:
    #include <iostream> 
    #include <conio.c> 
    using namespace std;
    
    int main()
    {
    char ch;
    char ch2;
    
    cout << "Your password ONE should end with an asterisk (*).\n";
    cout << "Enter your password :\n>> ";  
      
    while (ch = getch() != '*')
    {
        cout << "*";
    }
    
    cout << "\n\n\nYour password TWO should be 8 characters long.\n";
    cout << "Enter your password :\n>> ";
    
    for(int x = 0; x < 8; x++)
    {
    ch2 = getch();
    cout << "*";
    }
    
    cout << endl << endl << endl;
    system("pause");
    
      return 0;
    }

    I couldn't get '\n' to replace '*' successfully. If anyone knows why, share your knowledge !

  7. #7
    Registered User Daniel's Avatar
    Join Date
    Jan 2003
    Posts
    47

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, 01:59 AM
  2. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  3. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  4. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  5. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM