0

Hi guys,
I am looping through an array to print the values I entered in another loop before. The first method (showNombre()) returns a char array, the second one and Int.

Problem is my second one showEdad() is returning the address of the int and not the value entered before.

Here is the loop retrieving the info, p is a pointer to animal class, and ob[] is an array of the class.

for(int y=0; y<x; y++)
    {
        p = &ob[y];
        cout << "Nombre: " << p->showNombre() << endl;
        cout << "Edad: " << p->showEdad() << endl;
    }

Here below I post the loop for entering the data, it runs good so far.

for( int i=0; i<x; i++ )
    {
        cout << "Nombre: ";
        getline(cin, n);
        cout << "Edad: ";
        getline(cin, temp);
        if( ! ( istringstream(temp) >> e) ) e = 0;

        ob[i].setNombre(n);
        ob[i].setEdad(e);
    }

Any help is appreciated

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jonsca
1

Try instantiating a istringstream

istringstream iss(temp); //before line 7
if(!(iss >> e)) e = 0;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.