Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 If using strings in dev-c++
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hamid14




PostPosted: 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;
}

Surprised Surprised Thanks in advance.
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: 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 Razz
Kharybdis




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: