forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.46.cpp
More file actions
24 lines (19 loc) · 634 Bytes
/
Copy path9.46.cpp
File metadata and controls
24 lines (19 loc) · 634 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string>
#include <iostream>
std::string fixName(const std::string &name,
const std::string &prefix,
const std::string &postfix) {
// An easy way.
//std::string newName = prefix + " " + name + " " + postfix;
//return newName;
std::string newName = name;
newName.insert(0, prefix + " ");
return newName.insert(newName.size(), " " + postfix);
}
int main() {
std::cout << fixName("James", "Mr.", "Jr.") << std::endl;
std::string name, prefix, postfix;
std::cin >> name >> prefix >> postfix;
std::cout << fixName(name, prefix, postfix) << std::endl;
return 0;
}