forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex9_45.cpp
36 lines (29 loc) · 875 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
36
//! @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.");
return 0;
}
inline std::string
pre_suffix(const std::string &name, const std::string &pre, const std::string &su)
{
std::string ret(name);
ret.insert(0, pre);
ret.append(su);
return ret;
}