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 ...
随机推荐
- solr搜索分词优化
solr服务器配置好在搜索时经常会搜出无关内容,把不该分的词给分了,导致客户找不到自己需要的内容,那么我们就从配置词典入手解决这个问题. 首先需要知道自带的词典含义: 停止词:停止词是无功能意义的词, ...
- nginx的日志配置
本文转自:https://www.cnblogs.com/biglittleant/p/8979856.html 版权归属原作者!!!!!! nginx access日志配置 access_log日志 ...
- Install Local SQL In Mac OS
extends:http://www.cnblogs.com/maxinliang/p/3583702.html 一.安装 到MySQL官网上http://dev.mysql.com/download ...
- geotrellis使用(四十二)将 Shp 文件转为 GeoJson
前言 一个多月没有写博客了,今天尝试着动笔写点. 原因很多,最重要的原因是我转行了.是的,我离开了开发岗位,走向了开发的天敌-产品经理.虽然名义上是产品经理,但是干的事情也很杂,除了不写代码,其他的都 ...
- 在php cli下可以使用 STDIN 来实现标准输入
简单的例子: echo "请输入一个数字:"; $num = trim(fgets(STDIN)); echo "请再输入一个数字:"; $num1 = ...
- Java之JVM监控工具分享
Java之JVM监控工具分享 JVM的基本知识常用的也就是类加载机制,内存区域.分配.OOM,GC,JVM参数调优 几个链接自己看: 内存区域&类加载机制 分配策略&垃圾回收算法.收集 ...
- Eclipse使当前项目依赖另一个项目
实例说明 在Eclipse中可以创建多个项目实现不同的软件开发,也可以使用多个项目来开发单独的大型软件,每个项目负责单独的模块部门,这样可以使软件的模块分类更清晰,可以单独的维护每个模块部分.但是项目 ...
- 主机配置nginx后如何获取访问者IP
he你早的时候写了一个根据访问者ip查询天气的小接口,那时候还没得买域名,没有搞nginx,测试自然没有问题,然后随着一个小工具一块上线了,今天突然发现我的小工具有好几个人在使用了,就想写一个记录访问 ...
- 微信小程序开发笔记01
微信小程序开发的优势 1,不用安装,即开即用,用完就走.省流量,省安装时间,不占用桌面: 2,体验上虽然没法完全媲美原生APP,但综合考虑还是更优: 3,对于小程序拥有者来说,开发成本更低,他们可以更 ...
- 补充:javascript
写法分类:1.行内(内联)写在标签里面,以属性的形式表现,属性名是事件属性名例如:<button onClick="js代码"></button>2.内嵌写 ...