Enter the password to display the star number

Source: Internet
Author: User
Tags delete key

// Use * when the user enters the password. But if he fails. Delete with the delete key. On the screen, you can also see the effect of "one less after deletion"
/* Getch ():
Header file: conio. h
Function purpose: Read a character from the console, but it is not displayed on the screen.
Function prototype: int getch (void)
Returned value: read characters
For example:
Char ch; or Int ch;
Getch (); or CH = getch ();
Use getch (); wait for you to press any key, and then continue to execute the following statement;
Use CH = getch (); after you press any key, assign the ASCII code corresponding to the key character to CH, and then execute the following statement.
Easy to error: the header file is conio. h. Instead of stdio. h.
The specific effect of the escape character '/B' in C ++
Use a common program to demonstrate the difference between output results with this character and unused ones.

# Include <iostream. h>
Int main ()
{Cout <"ABC" <"VF"; // output abcvf}

# Include <iostream. h>
# Include <conio. h>
Int main ()
{Cout <"ABC" <'/B' <"VF"; // output abvf }*/

 

# Include <iostream>
# Include <conio. h>

Using namespace STD;

Int main ()
{
Int I = 0;
Char A [8];

Cout <"enter the password (the password cannot exceed 8 characters):" <Endl;
While (1)
{
A [I] = getch ();
If (A [I] = '/B') // important, E
{
Cout <'/B ';
Putch ('');
Cout <'/B ';
I --;
Continue;
}
If (A [I] = 13) // 13 is the Inter key.
{
A [I] = '/0 ';
Break;
}
Putch ('*');
I ++;
}
Cout <Endl;
Cout <;
System ("pause ");
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.