这个有点不理解 结构数组!

MikeDogSong 2003-05-28 11:54:28
struct __SysInfo /*定义结构,名称__SysInfo*/
{
int Index ;
TCHAR * szLabel ;
TCHAR * szDesc ;
}
/*定义结构变量数组
并且对数组赋值 是这个意思么?*/
sysmetrics [] =
{
SM_CXSCREEN, TEXT ("SM_CXSCREEN"),
TEXT ("Screen width in pixels"),
SM_CXFIXEDFRAME,TEXT ("SM_CXFIXEDFRAME"),
TEXT("..")
};

这么写,请问哪里错了?
struct __SysInfo
{
int Index ;
TCHAR * szLabel ;
TCHAR * szDesc ;
}sysmetrics [] ;
sysmetrics[]={....};


...全文
75 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zark 2003-05-29
  • 打赏
  • 举报
回复
这和结构没有什么关系,你的问题在于没有明白什么叫“aggregate assignment"(中文记不得了)。

例如:

int array[4]={1,2,3,4};
是可以的,但
int array[4];
array={1,2,3,4};
就不可以了。

JetKingLau 2003-05-29
  • 打赏
  • 举报
回复
typedef struct __SysInfo /*定义结构,名称__SysInfo*/
{
int Index ;
TCHAR * szLabel ;
TCHAR * szDesc ;
} _SysInfo;

_SysInfo sysmetrics[10];

for(int i=0;i<10;i++) {
sysmetrics[i].Index = ...;
strcpy(szLabel,"...");
}
leasun 2003-05-29
  • 打赏
  • 举报
回复
结构数组的初始化方法就是用{},其中依次给出各个数组成员的成员变量的初始值,这是C语言中规定的方法。
MikeDogSong 2003-05-29
  • 打赏
  • 举报
回复
Initializing Aggregates That Contain Aggregates
Some aggregates contain other aggregates — for example, arrays of arrays, arrays of structures, or structures that are composed of other structures. Initializers can be supplied for such constructs by initializing each one in the order it occurs with a brace-enclosed list. For example:

// Declare an array of type RCPrompt.
RCPrompt rgRCPrompt[4] =
{ { 4, 7, "Options Are:" },
{ 6, 7, "1. Main Menu" },
{ 8, 7, "2. Print Menu" },
{ 10, 7, "3. File Menu" } };

Note that rgRCPrompt is initialized with a brace-enclosed list of brace-enclosed lists. The enclosed braces are not syntactically required, but they lend clarity to the declaration. The following example program shows how a two-dimensional array is filled by such an initializer:

#include <iostream.h>

void main()
{
int rgI[2][4] = { 1, 2, 3, 4, 5, 6, 7, 8 };

for( int i = 0; i < 2; ++i )
for( int j = 0; j < 4; ++j )
cout << "rgI[" << i << "][" << j << "] = "
<< rgI[i][j] << endl;
}

The output from this program is:

rgI[0][0] = 1
rgI[0][1] = 2
rgI[0][2] = 3
rgI[0][3] = 4
rgI[1][0] = 5
rgI[1][1] = 6
rgI[1][2] = 7
rgI[1][3] = 8

idontlikenickname 2003-05-29
  • 打赏
  • 举报
回复
你那么写叫赋值,对于基本类型,比如int,float等还可以,可是数组和结构就不能这么干了.
原来的写法是定义的同时初始化,编译期间就定了,赋值一般在运行期(Runtime)执行.
shishiXP 2003-05-29
  • 打赏
  • 举报
回复
struct __SysInfo sysmetrics [] ;
sysmetrics[]={....};

这样不行
就像
int a[];
a={1,2,3};不行一样
bm1408 2003-05-29
  • 打赏
  • 举报
回复
agree up!

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧