Reading Lines from File in C++
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++的更多相关文章
- Java – Reading a Large File Efficiently--转
原文地址:http://www.baeldung.com/java-read-lines-large-file 1. Overview This tutorial will show how to r ...
- 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: $!"; ...
- 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 ...
- 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 ...
- 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, ...
- Python File I/O
File is a named location on disk to store related information. It is used to permanently store data ...
- GDCPC 2008:B Reading books
Problem B Reading books (Input File: book.in / Standard Output) In the summer vacation, LRJ wants to ...
- 实现类似tail -f file功能
python版本py3 tail -f file是打印最后10行,然后跟踪文件追加的内容打印出来. python3 以为本方式打开的话,不能回退(f.seek(-1,1)),所有以'rb'方式打开文件 ...
- File I/O
File I/O Introduction We'll start our discussion of the UNIX System by describing the functions ...
随机推荐
- RuntimeException: Type "nmethodBucket*", referenced in VMStructs::localHotSpotVMStructs in the remot
问题:使用jmap命令查看某个进程的堆情况时(jmap -heap 198376),抛异常如下: Attaching to process ID 198376, please wait...Excep ...
- js实现十分钟内在页面无任何操作,页面跳转至登陆页
// 如果10分钟没有操作,退出到登录页 var timer; function startTimer(){ clearTimeout(timer); timer=setTimeout(functio ...
- oracle 自定义比较函数
1>自定义比较函数,targetVal的值为字符串,例如:“>=90”,"2~8"等范围格式,dataVal值为字符串. create or replace funct ...
- java学习(二)--- 变量类型
变量声明 type identifier [ = value][, identifier [= value] ...] ; 局部变量: 1.局部变量声明在方法.构造方法.语句块中 2.局部变量在方法. ...
- Linux 下挂载新硬盘方法
Linux的硬盘识别: 一般使用”fdisk -l”命令可以列出系统中当前连接的硬盘 设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. 1.关闭服务器加上新硬盘 2.启动服务器,以r ...
- 【转载】python抓取网页时候,判断网页编码格式
在web开发的时候我们经常会遇到网页抓取和分析,各种语言都可以完成这个功能.我喜欢用python实现,因为python提供了很多成熟的模块,可以很方便的实现网页抓取.但是在抓取过程中会遇到编码的问题, ...
- ELK之使用heartbeat监控WEB站点
简介 无论您要测试同一台主机上的服务,还是要测试开放网络上的服务,Heartbeat 都能轻松生成运行时间数据和响应时间数据 Heartbeat 能够通过 ICMP.TCP 和 HTTP 进行 pin ...
- WebH
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- SpringMVC+MyBatis+Druid使用MySQL8.0.11版本
1.使用MySQL8.0.11版本,要使用5.1.45或其他高版本驱动jar包,我本地使用的是最新的8.0.11 2.更换了MySQL驱动后,报Cannot find class [com.aliba ...
- Cardinal and Ordinal Numbers
Cardinal Numbers Table of Cardinal Numbers Cardinal numbers from 1 through 1,000,000 1 one 11 eleven ...