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 ...
随机推荐
- GitLab push除发Jenkins事件
1.打开Jenkins项目配置 2.勾选Trigger builds remotely (e.g., from scripts) 3.Authentication Token随便填个内容(比方1234 ...
- layui---form表单模块
虽然对layui比较熟悉了,但是今天有时间还是将layui的form表单模块重新看一下. https://www.layui.com/doc/modules/form.html 一.更新渲染 layu ...
- M - 非诚勿扰 优先队列
来源 作为2013年699万应届毕业生中的一员,由于宏观经济的不景气,小明在毕业当天就华丽丽地失业了! 经历了千难万苦的求职过程,小明特别能理解毕业生的就业之难,所以,他现在准备创建一家专门针对IT人 ...
- 【转载】解决gridview空行时不显示的问题
问题: GridView控件应用很是广泛,通常将它与DataSourceControl搭配使用,当然也可以手工指定DataSource属性来完成数据绑定.如果数据源返回一个空行的数据集(例如查询不到指 ...
- 无网络 使用pip安装mxnet
# 在有网络的同系统机器上运行以下命令:pip download mxnet# 目前mxnet版本为1.3.0,执行后当前目录得到以下文件: # . # ├── certifi--py2.py3-no ...
- leetcode-Evaluate the value of an arithmetic expression in Reverse Polish Notation
leetcode 逆波兰式求解 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid ope ...
- LeetCode 206 Reverse Linked List 解题报告
题目要求 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5-> ...
- delphi操作sqlite3
Delphi SQLite 简明无废话上手指南SQLite下载http://www.sqlite.org/download.html SQLite FAQhttp://www.sqlitecn.org ...
- maven工程下添加oracle驱动包
maven工程手动安装oracle驱动包到本地仓库 下载ojdbc.jar包 这个当然是最好去官网下载了.http://mvnrepository.com这个仓库上有,具体页面地址为: http:// ...
- 关于什么是SpringMVC,和SpringMVC基于xml配置、注解配置、纯注解配置
首先我们先要了解一下,什么是SpringMVC? SpringMVC是Spring框架内置的MVC的实现.SpringMVC就是一个Spring内置的MVC子框架,也就是说SpringMVC的相关包都 ...