-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ex9_45.cpp
35 lines (29 loc) · 963 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
33
34
35
//! @author @TungWah @Alan
//! @date 4 Oct,2014.
//!
//! 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>
//! Exercise 9.45
std::string pre_suffix(const std::string& name, const std::string& pre,
const std::string& su);
int main()
{
std::string name("alan");
std::cout << pre_suffix(name, "Mr.", ",Jr.") << std::endl;
return 0;
}
inline std::string pre_suffix(const std::string& name, const std::string& pre,
const std::string& su)
{
auto ret = name;
ret.insert(ret.begin(), pre.begin(), pre.end());
ret.append(su);
return ret;
}