【发布时间】:2018-03-27 18:35:20
【问题描述】:
请帮助我理解我在这里做错了什么。
结构是
struct node
{
int value;
stack <int>losersStack;
};
主要是
int main()
{
int size;
printf("Enter size of arrary\n");
scanf("%d", &size);
node *arr = new node[size];
for(int i=0; i<size; i++)
{
printf("Enter a value\n");
scanf("%d", arr[i].value );
}
}
输入值时出现错误。 “blabla 中 0x55e5effe (msvcr100d.dll) 处未处理的异常:0xC0000005:访问冲突写入位置 0xcdcdcdcd。”
提前致谢!
【问题讨论】:
-
你为什么在 C++ 中使用
scanf? -
scanf("%d", &arr[i].value); -
@Barmar 我更习惯它而不是 cout.. 这是问题的一部分吗?
-
当你得到大小时,你似乎知道如何使用
scanf(但为什么在C++中首先使用scanf?),但是你忘记了如何在循环中使用它? -
如果你比较习惯,那你应该知道需要给出变量的地址。
标签: c++ arrays pointers struct initialization