金海佳学C++primer9.45/9.46
生活随笔
收集整理的這篇文章主要介紹了
金海佳学C++primer9.45/9.46
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
string加前綴和后綴
Practice 9.45
#include <iostream> #include <queue> #include <string> #include <vector> #include <algorithm> #include <list> #include <iterator> #include <cmath> #include <cstring> #include <forward_list> #include <sstream> using namespace std;string add_pre_post(string s, string pre, string post) {s.insert(0, pre);s.append(post);return s; }int main() {string s, pre, post;cin >> s >> pre >> post;cout << "s: " << s << endl;cout << "pre: " << pre << endl;cout << "post: " << post << endl;cout << add_pre_post(s, pre, post) << endl;return 0; }Output
Practice
s: Haijia pre: Ms. post: Jin Ms.HaijiaJin #include <iostream> #include <queue> #include <string> #include <vector> #include <algorithm> #include <list> #include <iterator> #include <cmath> #include <cstring> #include <forward_list> #include <sstream> using namespace std;string add_pre_post_2(string s, string pre, string post) {s.insert(0, pre);s.insert((int)s.length(), post);return s; }int main() {string s, pre, post;cin >> s >> pre >> post;cout << "s: " << s << endl;cout << "pre: " << pre << endl;cout << "post: " << post << endl;cout << add_pre_post_2(s, pre, post) << endl;return 0; }Output
s: Haijia pre: Ms. post: Jin Ms.HaijiaJin剛才矯情了。
總結
以上是生活随笔為你收集整理的金海佳学C++primer9.45/9.46的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 分析一下云ERP与本地ERP相比区别在哪
- 下一篇: 【随笔感悟】以大多数人的努力程度之低,根