首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

请教可以在自定义函数中调用结构体数组中的数据吗

2012-03-28 
求助:请问可以在自定义函数中调用结构体数组中的数据吗?[color#FF0000][/color]求助:请问可以在自定义函

求助:请问可以在自定义函数中调用结构体数组中的数据吗?
[color=#FF0000][/color]求助:请问可以在自定义函数中调用结构体数组中的数据吗?

[解决办法]
当然可以,请参考下面的例子:

C/C++ code
#include <iostream>using namespace std;struct ASTRUCT{    int a;    int b;};void printinfo(ASTRUCT arr[], int n){    for(int i = 0; i < n; ++i)    {        cout << arr[i].a << "\t" << arr[i].b << endl;    }}int main(int argc, char** argv){    ASTRUCT s1 = {1, 1};    ASTRUCT s2 = {2, 2};    ASTRUCT array_ASTRUCT[2] = {s1, s2};    printinfo(array_ASTRUCT, 2);    return 0;}
[解决办法]
当然可以啊,在main函数中,定义一下结构体就行啦,比如说结构体名为struct A{int a[10]};
在main函数就写 A x(随便写什么),然后就x.a[10]就行了

热点排行