练习8.1
istream& abc(istream& is)
{
string s;
is >> s;
cout << s;
s.clear();
return is;
}
练习8.2
abc(cin);
练习8.3
答:输入类型与i不符,或者输入结束标识
练习8.4
vector<string> s;
void abc(string s1)
{
string s2;
ifstream in(s1);
while(getline(in, s2))
s.push_back(s2);
}
练习8.5
vector<string> s;
void abc(string s1)
{
string s2;
ifstream in(s1);
while(in>>s2)
s.push_back(s2);
}
练习8.6
略
关于书店程序,lz在这里就不写了,想具体了解的同学请看原书。
练习8.9
istringstream& abc(istringstream& is)
{
string s;
is >> s;
cout << s;
s.clear();
return is;
}
练习8.10
vector<string> s;
void abc(string s1)
{
string s2;
ifstream in(s1);
while (getline(in, s2))
{
s.push_back(s2);
istringstream is(s2);
is >> s2;
}
}
练习8.11
string line,word;
vector<PersonInfo> people;
getline(cin,line);
istringstream record(line);
while(getline(cin,line))
{
PersonInfo info;
record>>info.name;//读取名字
while(record>>word)//读取电话号码
info.phones.push_back(word);//保持他们
people.push_back(info);//将此纪录追加到people末尾
}
练习8.12
答:因为希望用默认初始化
练习8.13
string line,word;
vector<PersonInfo> people;
ifstream in("filename");
while(getline(in,line))
{
PersonInfo info;
istringstream record(line);
record>>info.name;
while(record>>word)
info.phones.push_back(word);
people.push_back(info);
}
练习8.14
答:因为不想无意间修改他们的值。
标签:info,string,s2,练习,back,课后,习题,primer,line From: https://blog.csdn.net/m0_74384466/article/details/139250843