1.返回非局部对象的引用来修改值
char &get_val(string &s, string::size_type ix) {
return s.at(ix);
}
void func1() {
string s("This is a string.");
for (string::size_type i = 0; i < s.size(); ++i) {
if (s.at(i) == 'a')
get_val(s, i) = 'A';
}
cout << s << endl;
}
2.返回值可以是一个列表
vector<string> string_list() {
int x;
cin >> x;
switch (x) {
case 0:return {};
case 1:return { "saber" };
case 2:return { "saber","archer" };
case 3:return { "saber","archer","lancer" };
}
return {};
}
void func2() {
for (string i : string_list())
cout << i << ' ';
cout << endl;
}