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<c har>,
_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";
}
it gets there but the IF statement is returning an error.
conditional expression of type 'std::basic_string<_Elem,_
with
[
_Elem=char,
_Traits=std::char_traits<c
_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
{
cout<< command;
if (command = "north")
cout << "north";
else
cout <<"other";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, BTW, you'd better use
if (!command.compare("north") )
cout << "north";
else
cout <<"other";
if (!command.compare("north")
cout << "north";
else
cout <<"other";
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 :-)
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 :-)
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"
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";
if (!stricmp(command.c_str(),
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()
cout << "north";
else
cout <<"other";
ASKER
sweet.. thanks... I am using VisStud.net...thanks
ASKER
https://www.experts-exchange.com/questions/21408254/text-based-game-assistance-note-homework.html
thanks for your time