1

I recently shifted from Turbo C++(DOS BOX) to visual studio code. In Turbo C++, I used to create a star-password program like:

#include<iostream.h>
#include<conio.h>
void main()
{
      clrscr();
      char name[20],a[20];
      cout<<"Enter username: ";
      gets(name);
      cout<<"Enter password: ";
      a[0]=getch();
      cout<<"*";
      int i=0;
      while(ch[i]!=13)                 //to come out of loop when
                                       //enter key is pressed.
      {
            ++i;
            ch[i]=getch();             //no need to hit enter
                                       //after entering each character
            cout<<"*";
      }
      cout<<"Password created successfully!";

But as you know, the C++11 is a bit different, I can't use getch() there. I didn't get any other function except getch() in which there is no need to press enter key after each character input. Is there any alternate or any other way to do it?

xscorp7
  • 303
  • 4
  • 11
  • https://stackoverflow.com/questions/1413445/reading-a-password-from-stdcin – pm100 Oct 17 '17 at 15:50
  • 2
    Turning off password echoing requires OS-specific code. – Barmar Oct 17 '17 at 15:50
  • I don't understand what you're getting at with C++11 and `getch`. – chris Oct 17 '17 at 15:50
  • OS specific code? Whats that? I am just creating a password like interface in this program which will let the user enter characters and instead of displaying the characters, password will get displayed. tell me if I am not clear to you! – xscorp7 Oct 18 '17 at 08:27

0 Answers0