Computer Science Canada If using strings in dev-c++ |
Author: | hamid14 [ Thu Apr 29, 2010 11:15 am ] |
Post subject: | If using strings in dev-c++ |
I am using latest version of dev-c++ and i am trying to do an if with strings. so here's my code, i keep getting errors on the if line. #include <iostream> using namespace std; int money,exp,color; int main () { string action (""); cout << "Enter the action. Type shop for buying items, type battle to battle"; cin >> action; if (action ("battle") { cout << "You chose battle"; } system ("pause"); return 0; } ![]() ![]() |
Author: | CodeMonkey2000 [ Thu Apr 29, 2010 12:55 pm ] |
Post subject: | RE:If using strings in dev-c++ |
Try if (action=="battle"). Also you should #include<string> . And dev-C++ is not a compiler, what version of dev-C++ you use isn't that helpful. And it hasn't been upgraded in 5 year ![]() |
Author: | Kharybdis [ Thu Apr 29, 2010 5:23 pm ] |
Post subject: | RE:If using strings in dev-c++ |
You don't need to include <string> with the latest dev-C++ compiler. It's included with <iostream>. Although you can always be a freak and do it anyway; it doesn't hurt. Hamid, an if statement has to evaluate to true, which yours definately does not. In fact, you just typed: ' if ( ""("battle")), which is just gibberish. In fact, i've never even seen a declaration such as the one you have for the string. Why don't you just type 'string action;' without the quotes? When initializing strings, it's the same as any other variable, such as int. Unless you want to somehow convert the string to a character value. |