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. spring学习笔记-AOP

    1.aop:aspect oriented programming 面向切面编程 2.aop在spring中的作用:   提供声明式服务(声明式事务) 允许用户实现自定义切面 3.aop:在不改变原有 ...

  2. linux的基本操作(shell 脚本的基础知识)

    shell 脚本的基础知识 日常的linux系统管理工作中必不可少的就是shell脚本,如果不会写shell脚本,那么你就不算一个合格的管理员.目前很多单位在招聘linux系统管理员时,shell脚本 ...

  3. hibernate02环境的搭建

    hibernate: 持久层的框架!是一个开放源代码的对象关系映射框架(ORM)!之前我们访问数据库使用JDBC!对JDBC进行了轻量级的对象封装!是一个全自动ORM框架!(底层可以自动生成sql语句 ...

  4. js 表达式与语句

    引子:表达式和语句很基础,但是有时会犯错,比如: function(){}//报错 (function(){})//不报错 function f(x){ return x + 1 }()//报错 fu ...

  5. 把Oracle由归档模式改为非归档模式

    把Oracle由归档模式改为非归档模式 开始–>运行命令cmd进入命令行模式 1. 使用命令sqlplus以无日志形式打开如下: sqlplus /nolog; 2. 连接数据库dev.worl ...

  6. Mac OSX取消Apache(httpd)开机启动(转载)

    启动服务时提示Apache启动失败,80端口被占用.查看进程发现存在几个httpd. OS X自带Apache,可是默认是没有启动的.我也没有开启Web共享,怎么就开机启动了呢? 不知道是不是因为安装 ...

  7. Codeforces 570 - A/B/C/D/E - (Done)

    链接:https://codeforces.com/contest/570 A - Elections - [水] AC代码: #include<bits/stdc++.h> using ...

  8. 15.4-uC/OS-III资源管理(二值信号量)

    互斥信号量是 uC/OS 操作系统的一个内核对象, 与多值信号量非常相似,但它是二值的,只能是 0 或 1,所以也叫二值信号量, 主要用于保护资源. 1.如果想要使用互斥信号量,就必须事先使能互斥信号 ...

  9. filter过滤器实现验证跳转_返回验证结果

    1. 需求背景 需要对某个请求url进行拦截,模拟是否可以进入某一个接口,如果拦截需要返回数据false,别问我为何不用intercept拦截器. 2. web.xml <filter> ...

  10. android 知识汇总

    1.assets:不会在R.java文件下生成相应的标记,assets文件夹可以自己创建文件夹,必须使用AssetsManager类进行访问,存放到这里的资源在运行打包的时候都会打入程序安装包中, 2 ...