I want to enter password in asteriks and compare it from the file. I compare it but i cannot able to show it in asteriks.If someone knows please solve it ?

Lame way to do it ... ;)

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

int main()
{
	string pass = "";
	int a; 
	
	cout << "Enter password: ";
	
	do
	{
		a = _getch();
		pass += char(a);
		cout << "*";
		
	}while( a != 13 );
	
	cout << endl << "Password is: " << pass << endl;
	
	return 0;
}

Lame way to do it ... ;)

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

int main()
{
	string pass = "";
	int a; 
	
	cout << "Enter password: ";
	
	do
	{
		a = _getch();
		pass += char(a);
		cout << "*";
		
	}while( a != 13 );
	
	cout << endl << "Password is: " << pass << endl;
	
	return 0;
}

Thanks dear. Its too good.
Thanks again for solving my problem.

>_getch() isn't part of the C++ standard
There's not a portable way to do what the OP wants, so any viable solution will use things that aren't part of the standard.

>you can't backspace
That's an easy addition.

>and you're using conio.h
See my comment for getch. So far you haven't given a good reason why it's a "lame" solution. Incomplete, yes, but I challenge you to write a solution that doesn't start with something along those lines.

>I challenge you to write a solution that doesn't start with something along those lines.
Well, I already gave a link to my code snippet I wrote some time ago which started differently, though I'm not sure if it's any better as it relies on the windows header and it seems a little excessive.

>you haven't given a good reason why it's a "lame" solution
He said it first :]

But as usual, I guess you're right :P

>I challenge you to write a solution that doesn't start with something along those lines.
Well, I already gave a link to my code snippet I wrote some time ago which started differently, though I'm not sure if it's any better as it relies on the windows header and it seems a little excessive.

>you haven't given a good reason why it's a "lame" solution
He said it first :]

But as usual, I guess you're right :P

William your code is also working good but it is too long.

>William your code is also working good but it is too long.
Does your homework have a line limit or something? :icon_rolleyes:

> Does your homework have a line limit or something?
dear I have limit how long code is. But short and smart code is good as compared to long nad same codes. I think small codes are good if they give same output as long codes.

>I think small codes are good if they give same output as long codes.
There's more to code than output. Quicksort and bubble sort produce the same result, for example, but in all but exceptional cases, quicksort is vastly superior despite being quite a bit longer and much more complex.

This article has been dead for over six months. Start a new discussion instead.