【发布时间】:2014-08-24 20:59:15
【问题描述】:
在 C++ 中,
struct info
{
int lazy,sum;
}tree[4*mx];
初始化:
memset(tree,0,sizeof(tree))
意思是
tree[0].sum is 0 and tree[0].lazy is 0 ...and so on.
现在我想像这样初始化不同的值:
tree[0].sum is 0 and tree[0].lazy is -1 .... and so on.
在 For 循环中
for(int i=0;i<n;i++) // where n is array size
{
tree[i].sum=0;
tree[i].lazy=-1;
}
但在 memset 函数中,我无法用不同的值初始化结构数组。是否可以 ??
【问题讨论】:
-
不,单次调用 memset 是不可能的。使用
std::fill。
标签: c++ struct initialization memset