金海佳学C++primer 练习9.18/9.19
生活随笔
收集整理的這篇文章主要介紹了
金海佳学C++primer 练习9.18/9.19
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
讀取到deque/list并輸出
Practice9.18
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <list> #include <iterator> #include <cmath> #include <deque> #include <cstring> #include <forward_list> using namespace std;deque<string> strdeq;void print(deque<string> deq) {/*for(auto i : deq) {cout << i << " ";}cout << endl;*/auto it = deq.begin();for(; it != deq.end(); it++) {cout << *it << " ";}cout << endl; }int main() {/* in.txt: jin hai jia wang lang ding meng */freopen("in.txt", "r", stdin);string str;while(cin >> str) {strdeq.push_back(str); }print(strdeq);return 0; }Output
jin hai jia wang lang ding mengPractice 9.19
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <list> #include <iterator> #include <cmath> #include <deque> #include <cstring> #include <forward_list> using namespace std;deque<string> strdeq; list<string> strlst;void deq_print(deque<string> deq) {/*for(auto i : deq) {cout << i << " ";}cout << endl;*/auto it = deq.begin();for(; it != deq.end(); it++) {cout << *it << " ";}cout << endl; }void lst_print(list<string> lst) {for(auto i : lst) {cout << i << " ";}cout << endl; } int main() {/* in.txt: jin hai jia wang lang ding meng */freopen("in.txt", "r", stdin);string str;while(cin >> str) {strdeq.push_back(str); strlst.push_back(str);}cout << "print deque: " << endl;deq_print(strdeq);cout << "print list: " << endl;lst_print(strlst);return 0; }Output
print deque: jin hai jia wang lang ding meng print list: jin hai jia wang lang ding mengGod is dead.
總結
以上是生活随笔為你收集整理的金海佳学C++primer 练习9.18/9.19的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 下载qq群文件_pytho
- 下一篇: [机器学习][基础编程][pandas]