C++ Primer(第5版) 练习 9.19

练习 9.19 重写上题的程序,用list替代deque。列出程序要做出哪些改变。

环境:Linux Ubuntu(云服务器)
工具:vim

 

代码块
//头文件需要调整为list,同时deque的位置都换为list
/*************************************************************************
	> File Name: ex9.19.cpp
	> Author: 
	> Mail: 
	> Created Time: Mon 26 Feb 2024 08:38:42 PM CST
 ************************************************************************/

#include<iostream>
#include<list>
using namespace std;

int main(){
    list<string> str;
    string word;

    while(cin>>word){
        str.push_back(word);
        if(cin.get() == '\n'){
            break;
        }
    }

    list<string>::iterator it;
    for(it = str.begin(); it != str.end(); ++it){
        cout<<*it<<" ";
    }
    cout<<endl;

    return 0;
}
运行结果显示如下

C++ //练习 9.19 重写上题的程序,用list替代deque。列出程序要做出哪些改变。-LMLPHP

02-27 07:18