♪ c++ program crashing down crashing down ♪
Hi guys, I'm starting one program and I'm getting an error on this loop, and I'm just starting :S
Just after finishing it crashes
1 2 3 4 5 6 7 8 9 10 11 12
|
for(i=0; i<=n; i++)
{
cout << "Escriba el nombre del animal: " << endl;
getline(cin,nombre);
cout << " Escriba la edad: ";
getline(cin,temp);
if( ! ( istringstream(temp) >> edad) ) edad = 0;
(zoo+i)->setNombre(nombre);
(zoo+i)->setEdad(edad);
}
|
seriously?
Are you looping through the array?
if yes maybe you should change the condition in for loop.
i<n instead of i<=n
what do you mean??
I dropped the loop and used this instead
1 2 3 4 5 6 7 8 9 10 11
|
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);
}
|
That was thanks to you chingy3, as soon as I changed i<=x for i<x it got fixed.
Thanks man
Topic archived. No new replies allowed.