发现了一个对象的动态数组的问题,为了好看把程序简化了一下。就是不知道怎么录入对象数组,就像图里的一样,那个自动窗口里显示的变量只有本人最初录入a[0],其他的都没有录入。并且,这个对象数组不像普通的变量数组一样可以在调试环境里展开由a展开a[0],a[1],a[2]……而是只有一个a;

在本人原先的程序里,还会提示读取字符串出错,求指导

在本人原先的程序里,还会提示读取字符串出错,求指导
解决方案
30
#include <iostream>
using namespace std;
class test{
public:
int a;
};
int main(){
test *a = new test[3];
for (int i = 0; i < 3; ++i){
cin >> (a + i)->a;
}
for (int j = 0; j < 3; ++j){
cout << (a + j)->a << ” “;
}
cout << endl;
delete[] a;
return 0;
}
using namespace std;
class test{
public:
int a;
};
int main(){
test *a = new test[3];
for (int i = 0; i < 3; ++i){
cin >> (a + i)->a;
}
for (int j = 0; j < 3; ++j){
cout << (a + j)->a << ” “;
}
cout << endl;
delete[] a;
return 0;
}
