-1

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!!!

5

1 Answer 1

-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 << '*';
    }
}
2
  • 1
    This could work on windows but probably not other OSs.
    – drescherjm
    Dec 11, 2020 at 16:57
  • 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, 2020 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.