C++ //练习 10.29 编写程序,使用流迭代器读取一个文本文件,存入一个vector中的string里。

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;
}
运行结果显示如下
相关推荐
步菲2 小时前
springboot canche 无法避免Null key错误, Null key returned for cache operation
java·开发语言·spring boot
香蕉卜拿拿拿6 小时前
软件解耦与扩展的利器:基于C++与C#的插件式开发实践
c++
aigcapi6 小时前
RAG 系统的黑盒测试:从算法对齐视角解析 GEO 优化的技术指标体系
大数据·人工智能·算法
知远同学7 小时前
Anaconda的安装使用(为python管理虚拟环境)
开发语言·python
小徐Chao努力7 小时前
【Langchain4j-Java AI开发】09-Agent智能体工作流
java·开发语言·人工智能
CoderCodingNo7 小时前
【GESP】C++五级真题(贪心和剪枝思想) luogu-B3930 [GESP202312 五级] 烹饪问题
开发语言·c++·剪枝
柯慕灵7 小时前
7大推荐系统/算法框架对比
算法·推荐算法
adam-liu7 小时前
Fun Audio Chat 论文+项目调研
算法·语音端到端·fun-audio-chat
kylezhao20197 小时前
第1章:第一节 开发环境搭建(工控场景最优配置)
开发语言·c#
啃火龙果的兔子7 小时前
JavaScript 中的 Symbol 特性详解
开发语言·javascript·ecmascript