Reading Lines from File in C++

In C++, istringstream has been used to read lines from a file.

code:

#include <iostream>
#include <fstream>
#include <string>
#include <sstream> using namespace std; int main() {
ifstream fin("vocab.gbk.txt");
string line, word;
istringstream iss;
while (getline(fin, line)){
iss.clear();
iss.str(line);
while (iss >> word) {
cout << word << " ";
}
cout << endl;
}
return 0;
}

file:

</s> 0
, 15533134
的 9841198
。 9088518
年 2951309
在 2790829
是 2185996

Output:

</s> 0
, 15533134
的 9841198
。 9088518
年 2951309
在 2790829
是 2185996

Ref:

<<C++ Primer 5th 中文版>> P288

Reading Lines from File in C++的更多相关文章

  1. Java – Reading a Large File Efficiently--转

    原文地址:http://www.baeldung.com/java-read-lines-large-file 1. Overview This tutorial will show how to r ...

  2. learning Perl:91行有啥用? 88 print "\n----------------------------------_matching_multiple-line_text--------------------------\n"; 91 my $lines = join '', <FILE>;

    89 open FILE, "< file_4_ex_ch7.txt"     90     or die "cannot open file: $!"; ...

  3. a trick in reading and storing file in the exact way!

    read and write file is a very common operation regarding file mainuplation. However, the powerfull g ...

  4. Analysis about different methods for reading and writing file in Java language

    referee:Java Programming Tutorial Advanced Input & Output (I/O) JDK 1.4+ introduced the so-calle ...

  5. Apache POI – Reading and Writing Excel file in Java

    来源于:https://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/ In this article, ...

  6. Python File I/O

    File is a named location on disk to store related information. It is used to permanently store data ...

  7. GDCPC 2008:B Reading books

    Problem B Reading books (Input File: book.in / Standard Output) In the summer vacation, LRJ wants to ...

  8. 实现类似tail -f file功能

    python版本py3 tail -f file是打印最后10行,然后跟踪文件追加的内容打印出来. python3 以为本方式打开的话,不能回退(f.seek(-1,1)),所有以'rb'方式打开文件 ...

  9. File I/O

    File I/O Introduction     We'll start our discussion of the UNIX System by describing the functions ...

随机推荐

  1. 线程锁Lock

    from threading import Thread, Lock import time def func(): global n n -= 1 n = 10 t_list = [] for i ...

  2. hdu 2097 sky数(进制转换)

    Sky数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. laravel+阿里大于实现发送验证码短信

    一.短信服务使用阿里大于提供的短信接口 阿里大于官方网站上的接入流程: 在阿里大于申请接口后,需要做以下操作: 申请签名 申请短信模板 创建Accesskey,可以通过权限最大的Accesskey创建 ...

  4. 在微信下载app引导页代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 【Java线程安全】 — 常用数据结构及原理(未完结)

    本文主要记录自己对于多线程安全的学习,先来记几个线程安全模型. 首先最重要的当然是volatile和AQS了: 我们知道,整个java.cuncurrent包的核心就是volatile,CAS加自旋悲 ...

  6. ELK之使用filebeat收集系统数据及其他程序并生成可视化图表

    当您要面对成百上千.甚至成千上万的服务器.虚拟机和容器生成的日志时,请告别 SSH 吧.Filebeat 将为您提供一种轻量型方法,用于转发和汇总日志与文件,让简单的事情不再繁杂. 1,安装fileb ...

  7. Flv视频格式如何转换成MP4格式

    如何将flv视频格式转换成MP4格式呢?随着现在视频格式的不断多样化,视频格式转换的问题也成了现在生活中常见的问题,那么我们应该怎样将flv视频格式转换成MP4格式呢?下面我们就一起来看一下吧. 操作 ...

  8. 实体框架—Entity Framework

    简称EF,是微软以ADO.NET为基础所发展出来的对象关系对应(ORM)解决方案. EF就是用来处理数据的,与数据库打交道.但是底层还是用到了ADO.NET的那一套东西. 为什么叫对象关系对应解决方案 ...

  9. php 延迟静态绑定: static关键字

    abstract class DomainObject { public static function create() { return new self(); } } class User ex ...

  10. asp.net mvc 简单实现一个账号只能在一个地方登录

    原理:  假设用户在机器A登陆后,  这时用户再次在机器B登陆,会以当前会话的SessionID作为键,用户id作为值,插入dictionary集合中,集合再保存在application(保存在服务器 ...