64,682
社区成员
发帖
与我相关
我的任务
分享
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)
error("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:
error("unexpected ZIP code format");
}
}