我在使用结构编程时遇到问题。我想接受可以重复多次的(整数,字符)形式的输入。然后程序会将字符存储在数组中整数指示的位置。目前,问题是消息未定义且位置未定义。
struct MessagePiece
{
int location;
char message;
};
void readMessage( istream& in, Message message[] )
{
MessagePiece;
message[256];
Message message;
while ( !in.fail() )
{
in >> location; //I'm not sure why this counts as undefined as it is defined in the struct
if (location < 256, location >= 0)
in >> message[location];
}
return;
};