I want to type a word in, but i do not want to see the characters. Example: If i type "What" i want to see "****", but the words have to be stored in the '*' any ideas.
I know they is a way to clear the stream after i have typed a word but have failed to find it.

Is they a way to type a word in and then have in deleted while in prompt? This is just a function i am trying to write.

Hope it is clear to read.
// headers

{
float twoplayer(float w)
{
string p;
string x;
int charcount;
x = '*';
int i;


cout << "Enter a word" << endl;
cin >> p;
i = 0;
p.assign(p, i, p.ength());


}

Edited 3 Years Ago by Nick Evan: Fixed formatting

Clearing the input stream won't really erase characters off the screen. What you want to do sound like getting aynchronous input.

There isn't a standard portable way to read asynchronous input. One method is to use getch(), however that's only a compiler extension, so it may not always work on all compilers.

Another method is to use APIs, for example the WinAPI if you're developing on the Windows platform. You can also use multiplatform libraries such as ncurses for portable console APIs.

[torbecire].

O.k did not get what you said, but i am a beginner at C++. I will look around or try to find another way. Thanks

Hey, i got this managed to get this from a site and it has helped me out. I wonder if you knew a way fto enter characters one at a time while the program checks, if the letter I typed is the same as the character i put in the password.

#include <iostream>
#include <conio.h>
using namespace std;


int main()
{
int ch;
char pword[15];
int i = 0;
char guess[15];


puts ("Enter your password");
fflush(stdout);


while ((ch = getch()) != EOF
&& ch != '\n'
&& ch != '\r'
&& i < sizeof(pword) - 1)
{
if (ch == '\b' && i > 0)
{
printf("\b \b");
fflush(stdout);
i--;
pword = '\0';
}
else if (isalnum(ch))
{
putchar('*');
pword[i++] = (char)ch;
}
}


pword = '\0';


printf ("\nYou entered >%s<", pword);


cout << "Guess the word entered" << endl;
cin >> guess;


for(int i = 0; i < 15; ++i)
{
if(pword == guess)
{
cout << "EA";
}
else
{
cout << "BOO";
}


}
}

Edited 3 Years Ago by happygeek: fixed formatting

Either before or after the point where you print out the '*', check if the character entered is equal to the corresponding character in the string:

if (ch == myString[i])
    // character is correct
else
    // character is incorrect

Of course, if you wanted to compare it AFTERWARDS, just compare it with strcmp(), because == doesn't work with the old C-style strings.

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