If statements involving a string and a int

Hi everyone, I'm new here :).
I was looking for a way to query an answer from the user, and then, depending on their answer, choose a number for a variable.. The part of the code im stuck on is this:::

ftype = string
mType = double

1
2
3
4
5
cout << "Enter enemy Type" << endl;
cin >> ftype;
if (ftype= "Field")                
mType = 2; 


The error I'm experiencing is:
could not convert `(&ftype)->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const char*)"Field"))' to `bool'

I am using Dev C++ is that helps
Thank you for your time,
Blackened
if (ftype= "Field")
Check the equality symbol
removing the equality symbol results in

1
2
expected `)' before string constant
could not convert 'ftype' to 'bool' 
Did you try
if (ftype == "Field) //== is the equality symbol ?
That worked! Thank you!
I feel like an idiot now =p

also: is there a way to make it NOT case sensitive?
Last edited on
yes
You can convert it to uppercase or lowercase and that way, it will become identical.
http://www.cplusplus.com/forum/beginner/15368/page1.html#msg76089
Those functions are templated to handle any string type. You can simplify them just like I did for the titlecase() function at the bottom of my post.
BTW, converting to lowercase is typically safer than converting to uppercase.
Good luck!
Topic archived. No new replies allowed.