Link to home
Start Free TrialLog in
Avatar of chad
chad

asked on

passing variables to another function error..casting???

I am trying to pass a structrure, integer and a string to another function.
it gets there but the IF statement is returning an error.

conditional expression of type 'std::basic_string<_Elem,_Traits,_Ax>::_Myt' is illegal
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>,
            _Ax=std::allocator<char>
        ]

the cout in the function process command relays the correct string data that is input when in main


struct structRoom
  {
        int            Room_number;
        int            sound;
        string      Room_desc_short;
        int            exit[6];
        string      Room_desc_long;
        bool            Player_visited_already;
      
  };

*****inside int main function**
int Player_room_position = 1;
string command = "";
cin >>command;

Process_Command(Rooms, Player_room_position, command);
***********************


void Process_Command(structRoom Rooms[], int Player_room_indexed, string command)
{
      cout<< command;

      if (command = "north")
            cout << "north";
      else
            cout <<"other";
}


Avatar of chad
chad

ASKER

more of the exact code could be found here
https://www.experts-exchange.com/questions/21408254/text-based-game-assistance-note-homework.html
thanks for your time
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, BTW, you'd better use

     if (!command.compare("north"))
         cout << "north";
    else
         cout <<"other";
Avatar of chad

ASKER

compare??? I have not seen that one before... I'll play it a couple times
that dang double == gets me everytime... that is what I get for trying to learn VB and C++ at the same time

thanks AGAIN JKR.
any more of us meeting like this and someone may claim...pointpassing :-)
Avatar of chad

ASKER

is there a method to compare the values of strings without regard to case sensitivity?

ie... "north", "NoRtH" both return true when compared to "NORTH"
To avoid case-sensitivity, use

     if (!stricmp(command.c_str(),"north"))
        cout << "north";
   else
        cout <<"other";

You'll need to

#include <string.h>

If you're using a MS compiler, that should be

     if (!_stricmp(command.c_str(),"north"))
        cout << "north";
   else
        cout <<"other";

Avatar of chad

ASKER

sweet.. thanks... I am using VisStud.net...thanks