I need help with the if statement

Is it possible to make it so an If statement can read string?
I tried to do this but it doesn't work. (Im an extremely new at C++)
1
2
3
  if (username == "jay");
     cout << "So jay is your name?" << endl; //I am not wanting anything else
//just a way of letting if run with string 
Try this.

1
2
3
4
if (username == "jay"){
    cout << "So jay is your name?" << endl;
} //I am not wanting anything else
//just a way of letting if run with string 


You do not need a semi-colon at the end of the line after an if statement.
It says opperand type is incompatible ("std::string" and "*char:")
https://gyazo.com/fbc44ff6371a371b69f1b83e0d2ed9fb
Last edited on
What have you declared username as?
 
char *const username = "jay";
closed account (oy0Gy60M)
char *const username = "jay";

Use a string.

std::string username = "jay";
Last edited on
it says no operator "==" matches these operands "std::string"
This is what I have and I am getting no errors.

1
2
3
4
5
6
int main(){
	string username = "jay";
	if (username == "jay") {
		cout << "So jay is your name?" << endl;
	}
}
Last edited on
Topic archived. No new replies allowed.