istream& abc(istream& is)
{
string s;
is >> s;
cout << s;
s.clear();
return is;
}
abc(cin);
答:输入类型与i不符,或者输入结束标识
vector<string> s;
void abc(string s1)
{
string s2;
ifstream in(s1);
while(getline(in, s2))
s.push_back(s2);
}
vector<string> s;
void abc(string s1)
{
string s2;
ifstream in(s1);
while(in>>s2)
s.push_back(s2);
}
略
关于书店程序,lz在这里就不写了,想具体了解的同学请看原书。
istringstream& abc(istringstream& is)
{
string s;
is >> s;
cout << s;
s.clear();
return is;
}
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;
}
}
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末尾
}
答:因为希望用默认初始化
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);
}
答:因为不想无意间修改他们的值。