Hi all...
I am a new c++ learner.
I'm facing a little problem. according the code below
I try to display the output from the loop...
but no matter how I trying it still can not work....
here is my codes...
anyone can tell me which part am I wrong and how can I fix it back? thx...
#include <iostream>
using namespace std;
class Animal {
string name;
public:
Animal (string name="") : name(name) {}
void setName(string name) { this->name = name; }
void print() const { cout << name << endl; }
};
int main() {
int size;
string name;
cout << "Animal number ? = ";
cin >> size;
Animal *a;
a = new Animal[size];
for(int i=0; i<size; i++) {
cout << "Animal #" << (i+1) << " = ";
cin >> name;
}
cout << "Animal List" << endl
<< "===========" << endl;
for(int i=0; i<size; i++){
cout << name[i];
}
delete [] a;
return 0;
}