在这里,Student_info 是一个类。我试图用不同长度的字符串初始化它,但它总是给出相同大小的对象,当它应该取决于输入字符串长度时。有什么建议么?(名称和公司被定义为字符串变量,而不是字符数组)
Structure of class Student_info
{ string name, company;
int yr, age;
}
Student_info *s[5];
s[0]= new Student_info("Aakash Goyal","form MNNIT Allahabad",2,57);
cout<<endl<<s[0]->getCompany()<<" is the company"<<endl;
cout<<endl<<s[0]->getName()<<" is the name and the size is: "<<sizeof(*s[0]);
s[1]= new Student_info("Hare Krishna","Hare Krsna Hare Rama",1,34);
cout<<endl<<s[1]->getCompany()<<" is the company"<<endl;
cout<<endl<<s[1]->getName()<<" is the name and the size is: "<<sizeof(*s[1]);