-
Typing Words.
Is there a way to make a program respond to words? Like for instance, if I have this in a program:
Code:
cin >> comm;
if ( comm = "North" ) {
or would it be more like:
Code:
cin >> comm;
if ( comm = North ) {
...or am I just dreaming that it would be that simple?
Here is the error I get with this:
" invalid conversion from `const char*' to `char' "
-
Just use the string class, then you can use ==
Otherwise, you'd have to use the likes of strcmp()
Code:
#include <iostream>
#include <string>
int main() {
std::string bar;
bar = "hello";
if ( bar == "hello" ) {
std::cout << "Woo!" << std::endl;
}
return 0;
}