What is wrong with this small piece of code?

Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
using namespace std;

int main()
{
const string password = "qwerty";
string password1;
cout<<"Please enter password: ";
cin>> password1;
if (password1 = password)
cout<<"Password is correct";
cin.get();
}


Here's the error:

could not convert 'password1.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(& password)))' to 'bool'|


Thanks.
Comparison is done with ==, = is the assignment operator.
if (password1 = password)
this is not a comparison it is an assignment

if (password1 == password)
this is how you should compare them
Ofcourse! Thanks guys.
Topic archived. No new replies allowed.