<分区>
我最后是这样的,
struct init
{
CHAR Name[65];
};
void main()
{
init i;
char* _Name = "Name";
int _int = 0;
while (_Name[_int] != NULL)
{
i.Name[_int] = _Name[_int];
_int++;
}
}
标签 c++
<分区>
我最后是这样的,
struct init
{
CHAR Name[65];
};
void main()
{
init i;
char* _Name = "Name";
int _int = 0;
while (_Name[_int] != NULL)
{
i.Name[_int] = _Name[_int];
_int++;
}
}
最佳答案
给你的结构一个构造函数:
struct init
{
char Name[65];
init( const char * s ) {
strcpy( Name, s );
}
};
现在你可以说:
init it( "fred" );
即使没有构造函数,你也可以初始化它:
init it = { "fred" };
关于c++ - 初始化结构体中的数组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2244135/