Skip to content

Commit

Permalink
refactor : return string by value
Browse files Browse the repository at this point in the history
	modified:   ex9_45.cpp
  • Loading branch information
Mooophy committed Oct 4, 2014
1 parent 0eaf057 commit 6a8bd14
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ch09/ex9_45.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! @Alan
//! @author @TungWah @Alan
//! @date 4 Oct,2014.
//!
//! Exercise 9.45:
//! Write a funtion that takes a string representing a name and two other
Expand All @@ -12,21 +13,25 @@
#include <string>

//! Exercise 9.45
void
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::string name("alan");
std::cout << pre_suffix(name, "Mr.", "Jr.");

return 0;
}


void
pre_suffix(std::string &name, const std::string &pre, const std::string &su)
inline std::string
pre_suffix(const std::string &name, const std::string &pre, const std::string &su)
{
name.insert(name.begin(), pre.begin(), pre.end());
name.append(su);
auto ret = name;
ret.insert(ret.begin(), pre.begin(), pre.end());
ret.append(su);

return ret;
}

0 comments on commit 6a8bd14

Please sign in to comment.