Foros > C++: imprimir un campo de tipo string

  1. stomba

    Mensajes [1] - Enviado el Lunes 28 de Abril de 2008 a las 13:34hs

    Tengo un arbol binario de este tipo:

    struct node{
    string info;/*load name of the function that we want to execute*/
    int reward;/*reward of taking this action*/
    struct node *left ; /*child*/
    struct node *right; /*brother*/
    };

    typedef struct node *nodes;

    nodes r,m,a,b,c,d,a1,a2,a3,a4,a5,a6,a7,a8;

    Y luego? en el main tengo algo como:

    string s;
    r=new node;//root node with all the actions

    r->info="Actions";
    r->reward=0;
    r->right=NULL;
    r->left=a1;

    d=r ;//esta ser? el puntero auxiliar para ir corriendo todo el arbol
    ?
    printf("%s
    ",d->info);


    Aqui es cuando me da error, como seria para poder imprimir el campo info del nodo r?

    Gracias ante todo

  2. ?lvaroMGH

    Mensajes [5] - Enviado el Miércoles 14 de Mayo de 2008 a las 11:59hs

    si la declaraci?n
    string info;/*load name of the function that we want to execute*/
    es un string de C++ entonces no es soportado por printf().

    Prueba:
    printf("%s", (d->info).c_srt());

    Aunque lo mejor ser?a usar cout en lugar de printf:

    #include
    #include
    using namespace std;
    ...
    cout << d->info;


responder

Para poder responder a este tema tenes que ingresar. Si no tenes una cuenta podes registrarse gratis..

publicidad

API DE FACEBOOK
GOOGLE CALENDAR API
GOOGLE MAPS API