struct付初值的问题

ddddfbb 2004-08-10 10:28:23
typedef struct tagSPS { //定义结构

char szPm[10]; //品名

int Lx; //0-GJ 1-XS

char szSl[10]; //数量

char szDj[10]; //单价

char szJe[10]; //金额

} SPS;
SPS Sps[]={//信息

{"红梅",0,"1000","30","30000"},

{"黄梅",0,"1000","29","29000"},

{"绿梅",0,"1000","28","28000"},

{"青梅",0,"1000","27","27000"},

{"白梅",0,"1000","31","31000"},

{"红梅",1,"1000","30","30000"},

{"黄梅",1,"1000","29","29000"},

{"绿梅",1,"1000","28","28000"},

{"青梅",1,"1000","27","27000"},

{"白梅",1,"1000","31","31000"}};


错在那里了 定义是在.h里 付值是在cpp里 不是全局的
...全文
196 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
evlon 2004-09-01
放在CPP文件中
回复
ddddfbb 2004-08-11
ft
要在类里面 定义
回复
eliner 2004-08-10
.cpp文件里面有没有#include 头文件呀?
回复
ddddfbb 2004-08-10
是在mfc里
付值 和 定义不在一起
定义 SPS Sps[23]

然后付值该怎么付

在.h文件里不能付初值吗
回复
kvw3000 2004-08-10
详细点
回复
hooliganstreet 2004-08-10
错误信息贴出来吧,看上面的定义是对的
回复
Cline 2004-08-10
我把它们全放在main()上面,没问题呀.
回复
benhuangua 2004-08-10
up
用extern
另外,在.cpp中不使用#include么?
回复
Cline 2004-08-10
.h
extern SPS Sps[];

.cpp
SPS Sps[]={//信息

{"红梅",0,"1000","30","30000"},

{"黄梅",0,"1000","29","29000"},

{"绿梅",0,"1000","28","28000"},

{"青梅",0,"1000","27","27000"},

{"白梅",0,"1000","31","31000"},

{"红梅",1,"1000","30","30000"},

{"黄梅",1,"1000","29","29000"},

{"绿梅",1,"1000","28","28000"},

{"青梅",1,"1000","27","27000"},

{"白梅",1,"1000","31","31000"}};
回复
ddddfbb 2004-08-10
可能我没说清楚 再说一次
typedef struct tagSPS { //定义结构

char szPm[10]; //品名

int Lx; //0-GJ 1-XS

char szSl[10]; //数量

char szDj[10]; //单价

char szJe[10]; //金额

} SPS;
SPS Sps[10];

要给他付以下的值 该怎么做
{//信息

{"红梅",0,"1000","30","30000"},

{"黄梅",0,"1000","29","29000"},

{"绿梅",0,"1000","28","28000"},

{"青梅",0,"1000","27","27000"},

{"白梅",0,"1000","31","31000"},

{"红梅",1,"1000","30","30000"},

{"黄梅",1,"1000","29","29000"},

{"绿梅",1,"1000","28","28000"},

{"青梅",1,"1000","27","27000"},

{"白梅",1,"1000","31","31000"}};

我不想1个一个付值 有什么简便的方法吗
回复
laker_tmj 2004-08-10
up learn
回复
ddddfbb 2004-08-10
就放在 xxDlg.h 里定义这个结构

在xxDlg.cpp 里付值 该怎么付 我不想一条条付,太麻烦 就象上面一样付值就好了
回复
flyelf 2004-08-10
如果是在.h文件,当被多个文件include的时候,会产生多次副本的错误,所以要放在cpp文件中,如果其它文件要用这个变量,那么使用extern声明
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-08-10 10:28
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……