In this example from The C++ Programming Language 4th edition, chapter 8
I get error char[2] not assignable
and char [5] not assignable
. I'm using clang 4.9. What am I missing?
struct Address{
string name;
int number;
string street;
string town;
char state[2];
char zip[5];
Address(const string n,int nu,const string & s,
const string& t,const string& st,int z);
};
Address::Address(const string n,int nu,const string & s,
const string& t,const string& st,int z)
:name{n},
number{nu},
street{s},
town{t}
{
if(st.size()!=2)
cout<<"state abbreviation should be two characters";
state={st[0],st[1]};
ostringstream ost;
ost<<z;
string zi{ost.str()};
switch(zi.size()){
case 5:
zip={zi[0],zi[1],zi[2],zi[3],zi[4]};
break;
case 4:
zip={'0',zi[0],zi[1],zi[2],zi[3]};
break;
default:
cout<<"unexpected zip code format";
}
}