If Statements and strings

I'm new to learning C++ and am currently working through Stroustrup's Principles and Practice book.

For one of the exercises, I created the following function to analyze if a word (entered by the user) is a conjunction or not:

1
2
3
4
5
6
7
string w;

bool conjunction() {
	cin >> w;
	if (w == "and" || w == "or" || w = "but") return true;
	else return false;
}

However, this is generating the following error:

error C2679: binary '||': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

What am I doing wrong here? I've searched around for a while now but can't figure out why this wouldn't get compiled.
Last edited on
== tests for equality, = is an assignment.

The whole function can be simplified to:
1
2
3
bool conjunction(string w) {
	return (w == "and" || w == "or" || w == "but");
}


<Edit: Well, not anymore because you edited your post...>
Last edited on
I really should check over my code better...the = was of course a typo.

Thanks for the simplification tip.
Topic archived. No new replies allowed.