Hide input with ****

How do I make it so Player 2 cannot see what Player 1 is currently typing?

here is the game concept:

1
2
3
4
5
6
7
cout << "How to Play:" << endl;
cout << "Player 1 chooses to Attack 'head' or 'body'" << endl;
cout << "Then, Player 2 will choose to shield 'head' or 'body'." << endl;
cout << "If Player 2 sheilds the same direction as Player 1's attack, then the attack is blocked." << endl;
cout << "If Player 2 does not shield the attack, then Player 2 will lose 1 HP. There is a 15% crit chance for +1 DMG." << endl;
cout << "Then Player 2 Attacks, and Player 1 defends." << endl;
cout << "Each player has 5 HP." << endl << endl;
http://www.cplusplus.com/forum/general/3570/

So, if you are on Windows maybe this will do the job:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
#include <conio.h>
int main(){
   std::string pass = "";
   char ch;
   while((ch = getch()) != '\r'){
      pass.push_back(ch);
      std::cout << '*';
   }
   std::cout << std::endl << pass;
}
do i need std::

if i have the using namespace std;?
do i need std::

if i have the using namespace std;?

No. But it is considered bad practice to use it, std:: is a better choice -
http://bfy.tw/4JE3
If you know that you'll need commands with other namespaces than std, then the compiler might get confused with using namespace std; . You should use it only when you know you won't be using commands out of std.
Topic archived. No new replies allowed.