Passwords

I Am new at c++ and i need a little help. I want to make a Password for my program and i dont no how to. can someone help me please??

Thanks,
MM
Something like that?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

const string password("password"); //type a password to quotation marks

int main(){
	string x;
	cout << "Type the password to enter a program: ";
	cin >> x;
	if(x==password){
		cout << "Hello\n";
	}
	else{
		cout << "Wrong password!\n";
	}
}
Last edited on
Shouldn't you also include the string header?

#include <string>
Last edited on
Nope, u don't have to, it works without it.
That only works on Visual Studio, which automatically includes standard headers (for some reason).
You do have to #include <string>
Yay, I'm right at something finally!!
Thanks This Helped Me. I Finished My Project I Was Working On

Thank you,
MM
Topic archived. No new replies allowed.