【发布时间】:2019-08-13 17:25:28
【问题描述】:
我有一个 C++ 结构
struct Line {
int date;
int time;
float open;
float high;
float low;
float close;
float sd;
float long_mo;
float short_mo;
};
8 个字段。 我想用循环填充它。
int fields_count=1;
while (fields_count<=8) {
// get digit from outer sourse. I dont need help here.
// First iteration puts to 1 field, Second iteration puts to 2 field and so on up to last field of struct
fields_count++;
}
【问题讨论】:
-
您不能在 C++ 中迭代结构字段(很遗憾:()。
-
如果所有字段都具有相同的类型,这会更容易。
-
if (fields_count == 1) line.date = sourse.as_int();等等
标签: c++