forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ex9_45.cpp
32 lines (28 loc) · 827 Bytes
/
ex9_45.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// @author @TungWah @Yue Wang
// @date 4 Oct, 2014. Oct, 2015.
//
// Exercise 9.45:
// Write a funtion that takes a string representing a name and two other
// strings representing a prefix, such as “Mr.” or “Ms.” and a suffix,
// such as “Jr.” or “III”. Using iterators and the insert and append functions,
// generate and return a new string with the suffix and prefix added to the
// given name.
//
#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;
// Exercise 9.45
auto add_pre_and_suffix(string name, string const& pre, string const& su)
{
name.insert(name.begin(), pre.cbegin(), pre.cend());
return name.append(su);
}
int main()
{
string name("Wang");
cout << add_pre_and_suffix(name, "Mr.", ", Jr.") << endl;
return 0;
}