dimanche 1 mars 2015

printing out elements of an array of structs


I can't seem to figure out what I am doing wrong ... I am writing a program to play the game quatro, which is a board game kind of like tic tac tow. In the game their are 16 unique pieces in which each piece has four "traits". (Tall or Short , Black or White , Hollow or Filled, Square or Circle)


I created a structure "pieces" in which "traits" is a member. I refer to traits as W for white, T for Tall, H or hollow ....


Anyway, I am just trying to create an array which holds all available pieces and displays them in a separate scaled down program. However I can't seem to print out the elements of the available array.


the error i am getting is


error: not match for 'operator <<' in std:cout << available[0]'


Here is what I am trying now ...



#include <iostream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <algorithm>

using namespace std;

struct Pieces{

string traits;

};

int main()
{
Pieces p1;
p1.traits = "WSHR";

Pieces p2;
p2.traits = "BSHR";

Pieces p3;
p3.traits = "WTHR";

Pieces p4;
p4.traits = "BTHR";

Pieces available [4] = {p1.traits,p2.traits,p3.traits,p4.traits};

cout << available[0];


return 0;


}


I added a bunch of library's hoping that was the problem. When I dereference the available array ( &available[0] ) the address prints out but I can't seem to figure out how to print the value in the first slot of the array.


Any help would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire