password via istream (new thread)

This is a discussion on password via istream (new thread) within the C++ Programming forums, part of the General Programming Boards category; sorry folks...i had quoted the question in the book (by Stroustrup) wrongly.. the actual question was write manipulators that turn ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Location
    india->tamil nadu
    Posts
    18

    Thumbs up password via istream (new thread)

    sorry folks...i had quoted the question in the book (by Stroustrup) wrongly..
    the actual question was

    write manipulators that turn character echoing on and off

    this is the correct one. unlike a command, itz just a quote..hope you understand.
    pease refer this for more details.

    its on the exercise section of the chapter 21.Streams which is at the end of it, and page is 656.

    The C++ Programming Language 3rd ed
    from the Creator Of C++,
    Bjarne Stroustrup.
    Addison Wesley Publications.
    Last edited by cyb3r; 04-27-2007 at 04:45 AM.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Stroutroup is just trying to hammer in the idea of an iostream manipulator. I don't think he ever intended that the answer to the question would be PORTABLE. Look up how to do this on your platform, then write a manipulator that does it.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Location
    india->tamil nadu
    Posts
    18
    and the problem no. is 19.

    i am trying out this one...hope i get it.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    I think you've gotten your answer as well as you are going to get it. We don't know a standard way to do it. Stroustrup was probably expecting you to use a non-standard method platform dependent method to do that.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Here's a Linux C program equivalent to the Windows pause command. It may give you an idea.
    Code:
    #include <unistd.h>
    #include <termios.h>
    #include <string.h>
    
    int main()
    {
      printf("Press any key to continue.\n");
      struct termios trm;
      memset(&trm, 0, sizeof(struct termios));
      cfmakeraw(&trm);
      struct termios old;
      tcgetattr(STDIN_FILENO, &old);
      tcsetattr(STDIN_FILENO, TCSAFLUSH, &trm);
      char buf;
      read(STDIN_FILENO, &buf, 1);
      tcsetattr(STDIN_FILENO, TCSAFLUSH, &old);
      return 0;
    }
    Note that cfmakeraw fills the termios structure with settings that put the terminal in "raw" mode: no echo and no waiting for a full line.
    For your purposes, you'll want to get the old mode with tcsetattr, disable the ECHO bit in the c_lflag field, and set the modified attributes. To enable echo again, do the reverse. To be entirely correct, you should store the initial mode in the stream using the stream storage interface (now that's an interesting little beast - a good thing to learn about, even if its use is limited in general) and listen to the stream shutting down event (erase_event) to restore the original state. Otherwise, the program shutting down in no-echo mode might screw up your terminal, and you don't want that.

    Of course all this applies only to POSIX. Windows is an entirely different matter. As we said, there's no portable way.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 04:14 AM
  2. Thread Prog in C language (seg fault)
    By kumars in forum C Programming
    Replies: 22
    Last Post: 10-09-2008, 01:17 PM
  3. pointer to main thread from worker thread?
    By draegon in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2005, 06:35 AM
  4. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  5. Password prompt in unix w/o \b
    By rafe in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 08:54 AM

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