[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

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";
}


0
chad
Asked:
chad
  • 4
  • 3
1 Solution
 
chadAuthor Commented:
more of the exact code could be found here
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21408254.html
thanks for your time
0
 
jkrCommented:
    if (command = "north")
         cout << "north";
    else
         cout <<"other";

should read

     if (command == "north") // TWO '='
         cout << "north";
    else
         cout <<"other";

otherwise that evaluates to 'if (command)', whihc causes this error.
0
 
jkrCommented:
Oh, BTW, you'd better use

     if (!command.compare("north"))
         cout << "north";
    else
         cout <<"other";
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
chadAuthor Commented:
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 :-)
0
 
chadAuthor Commented:
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"
0
 
jkrCommented:
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";

0
 
chadAuthor Commented:
sweet.. thanks... I am using VisStud.net...thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now