C++ Primer(第5版) 练习 10.29
练习 10.29 编写程序,使用流迭代器读取一个文本文件,存入一个vector中的string里。
环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp
/*************************************************************************
> File Name: ex10.29.cpp
> Author:
> Mail:
> Created Time: Mon 04 Mar 2024 10:43:46 AM CST
************************************************************************/
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<iterator>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
vector<string> str;
ifstream in ("10.29.txt");
istream_iterator<string> str_it(in);
istream_iterator<string> eof;
while(str_it != eof){
str.push_back(*str_it++);
}
for(const auto s : str){
cout<<s<<" ";
}
cout<<endl;
return 0;
}
运行结果显示如下
