How can I replace the input character with the "*" character? Everything should happen at the time of entering (like entering a password when registering on the site). Thanks for the answer!!!
Asked
Active
Viewed 359 times
-1
-
2You can't do that with just standard c++ directly. You need some OS api or library that makes use of an OS api. – drescherjm Dec 11 '20 at 16:46
-
1Related/duplicates (I think these just remove echo, not replace it with stars): https://stackoverflow.com/questions/6899025/hide-user-input-on-password-prompt https://stackoverflow.com/questions/1413445/reading-a-password-from-stdcin – Yksisarvinen Dec 11 '20 at 16:47
-
1This question is a duplicate: https://stackoverflow.com/questions/5316562/is-it-possible-to-hide-a-password-defined-within-c-code – πάντα ῥεῖ Dec 11 '20 at 16:47
-
1Loads of duplicates: https://www.google.com/search?rlz=1C1CHBF_deDE833DE833&biw=1600&bih=789&sxsrf=ALeKk009fQoRQPc8i8OIGH_t57H1NFGWNg%3A1607704204747&ei=jJ7TX7X9LIvgkgWXrI_IAg&q=site%3Astackoverflow.com+%22c%2B%2B%22+hide+password&oq=site%3Astackoverflow.com+%22c%2B%2B%22+hide+password&gs_lcp=CgZwc3ktYWIQAzoECAAQR1Djrz5Y2M4-YL3UPmgAcAJ4AIABY4gBuwiSAQIxM5gBAKABAaoBB2d3cy13aXrIAQjAAQE&sclient=psy-ab&ved=0ahUKEwi185vwrMbtAhULsKQKHRfWAykQ4dUDCA0&uact=5 – πάντα ῥεῖ Dec 11 '20 at 16:47
-
Does this answer your question? [how to show enter password in the form of Asterisks(\*) on terminal](https://stackoverflow.com/questions/25990966/how-to-show-enter-password-in-the-form-of-asterisks-on-terminal) – niz_sh Dec 14 '20 at 04:45
1 Answers
-1
An easiest way, i think like this:
#include <iostream>
#include <string>
#include <conio.h>
int main()
{
std::string str;
char ch;
std::cout << "enter the text: ";
while((ch = _getch()) != 13) //enter type
{
str+= ch;
std::cout << '*';
}
}

niz_sh
- 475
- 2
- 5
- 16
-
1
-
I did not downvote however I assume there are at least two reasons someone would. The first reason is the person asking never mentioned that they we using MS windows instead of Android or some other OS. A second reason is there is no description of the code. – drescherjm Dec 11 '20 at 17:36