structure for mailing list

Hi,

i am now learning how to use structure in c++ and build one for a mailing list. But it does not work and i cannot figure out why. My code is:

#include <iostream>
#include <string>

using namespace std;


int main()
{
const int MAX_ENTRIES=5;

struct mailing{
char title[3];
char name[60];
char address1[60];
char address2[60];
int zip;
char city[60];
};

struct mailing list[MAX_ENTRIES];

list[0].title="Mr";
list[0].name="my name";
list[0].address1="my address";
list[0].address2=" ";
list[0].zip=0000;
list[0].city="my city";
return 0;
}


and the message of the builder is:

C:\Documents and Settings\jn\My Documents\c++\exercises\mailing list\main.cpp||In function `int main()':|
C:\Documents and Settings\jn\My Documents\c++\exercises\mailing list\main.cpp|22|error: ISO C++ forbids assignment of arrays|
C:\Documents and Settings\jn\My Documents\c++\exercises\mailing list\main.cpp|23|error: incompatible types in assignment of `const char[8]' to `char[60]'|
C:\Documents and Settings\jn\My Documents\c++\exercises\mailing list\main.cpp|24|error: incompatible types in assignment of `const char[11]' to `char[60]'|
C:\Documents and Settings\jn\My Documents\c++\exercises\mailing list\main.cpp|25|error: incompatible types in assignment of `const char[2]' to `char[60]'|
C:\Documents and Settings\jn\My Documents\c++\exercises\mailing list\main.cpp|27|error: incompatible types in assignment of `const char[8]' to `char[60]'|
||=== Build finished: 5 errors, 0 warnings ===|


could someone hep me?

thanks in advane and kind regards
Last edited on
don't use char arrays.

use strings.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// BAD
struct mailing{
char title[3];
char name[60];
char address1[60];
char address2[60];
int zip;
char city[60];
};


// GOOD
struct mailing{
string title;
string name;
string address1;
string address2;
int zip;
string city;
};


Note that you can use char arrays if you really want to, but you can't assign them with the = operator like that. You have to use strcpy().

Don't bother, though. strings are much easier.
As Disch say, character arrays are not good.. awkward.. took me a while to remember how to use them properly :

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
#include <stdio.h>
#include <string.h>

//using namespace std;


int main()
{
const int MAX_ENTRIES=5;

struct mailing{
char title[3];
char name[60];
char address1[60];
char address2[60];
int zip;
char city[60];
};

mailing list[MAX_ENTRIES];

strcpy(list[0].title,"Mr");
strcpy(list[0].name,"my name");
strcpy(list[0].address1,"my address");
strcpy(list[0].address2," ");
list[0].zip=0000;
strcpy(list[0].city,"my city");


return 0;
}
thanks a lot!!!
Topic archived. No new replies allowed.