array of structs problem

Heey , i Have construct an array in each cell of the array is a struct , and i try to send the array to a function to read from int but it dose not work.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 #include<iostream>
#include<string>
using namespace std;
const int size =5;
void read ( struct bank arr[]);
int main()
{
	struct bank{
		int accnum;
		string cfn;
		string cln;
		int total;
		string blist;
	};


	bank arr[size];


	read(arr);

	return 0;
}

void read ( struct bank arr[])
{

	cin>>arr[0].bank.cfname;// it dose not read any thing .


}






did it really compile ??

cin >> arr[ 0 ].bank.cfname;
the bank structure doesn't have any member named cfname

I think what you meant is :
cin >> arr[ 0 ].cfn; ?

And the struct should be outside main()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
using namespace std;

struct bank
{
    int accnum;
    string cfn;
    string cln;
    int total;
    string blist;
};

void read ( bank arr[] );

int main()
{
    const int size =5;
    bank arr[size];

    read(arr);

    return 0;
}

void read ( bank arr[] )
{
    cin>>arr[0].cfn;
}


btw, try to improve the white spaces & indentation, it will really make the code cleaner
Last edited on
Thank you ^^
Topic archived. No new replies allowed.