Thread: Command Line (cin) Hiding & Counter Using C++

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Command Line (cin) Hiding & Counter Using C++

    Hi.

    I was wondering how to:

    1) hide what a user types, but still read the keys.

    I am working on a program that is involves password protection. I need a way to asks for the pass, but not display it openly just when logging onto any OS. A good example is logging onto linux. It asks for the password, but it does not display what the user enters.

    2) code a counter that uses the clock as a seed.

    For example let say this is the code:

    cout << "testing";
    cout << "1 ";
    ------------------3 second delay
    cout << "2 ";
    ------------------3 second delay
    cout << "3 ";

    In other word, is there a way to code some type of delay or counter?

    Thanks,
    Kuphryn

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Code:
    #include<windows.h>
    #include<iostream>
    using namespace std;
    int main()
    {
    cout<<"1"<<endl;
    Sleep(3000);
    cout<<"2"<<endl;
    Sleep(3000);
    cout<<"3"<<endl;
    return 0;
    }
    for 1) check out getch() which gets an unbuffered keypress without echo. getche() does the same but with echo.
    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

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Thanks.

    Kuphryn

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Thanks.

    getch() & getche()

    Is it one character per? If yes, it would need to be in a loop structure

    Kuphryn

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    yes thats right.
    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

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay.
    I tried implementing:

    getch();

    and

    getche();

    VC++ 6 responded with:

    c:\x.cpp(179) : error C2039: 'getch' : is not a member of 'basic_istream<char,struct std::char_traits<char> >'

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  2. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  3. Flowchart Question
    By dmkanz07 in forum C Programming
    Replies: 1
    Last Post: 04-08-2007, 11:33 AM
  4. getline(function)??
    By dac in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 12:42 PM
  5. Counter Heap Sort
    By Achillles in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 12:17 PM