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 ...
随机推荐
- ef报错:实体类型XXX不是当前上下文的模型的一部分。
可能原因:.net框架版本与实体框架版本不匹配,比如:.net框架版本为4.5.实体框架版本为6.2. 解决方法:将实体框架版本降到6.0.
- Scala 中方法扩展实践
前言 这个名字不知道取得是否合适,简单来说要干的事情就是给某个类型添加一些扩展方法,此场景在各种语言中都会用到,比如 C# 语言,如果我们使用一个别人写好的类库,而又想给某个类库添加一些自己封装的方法 ...
- Enterprise Craftsmanship
转自:http://enterprisecraftsmanship.com/2015/04/13/dto-vs-value-object-vs-poco/ DTO vs Value Object vs ...
- brew 源 & pip 源
brew源: https://www.zhihu.com/question/31360766 摘要 1. 替换formula 索引的镜像(即 brew update 时所更新内容) cd " ...
- js模拟发送 FormData数据
后台express需要connect-multiparty模块接收formData的数据类型 class ourFormData { constructor(data, rs) { return ne ...
- 查看集成环境 phpstudy 中 mysql 版本号
1. 打开面板 2.其他选项菜单 3. Mysql工具 4. mysql命令行 5.输入密码,回车.phpstudy mysql默认 root 6.运行 select version();
- 21、bootstrap框架
http://www.bootcss.com/ Bootstrap 插件==全部依赖 jQuery== 请注意,Bootstrap 的所有 JavaScript 插件都依赖 jQuery,因此 jQu ...
- js的小知识7
1.函数都有返回值...... 而方法的本质也是函数,所有也有返回值. Document.getElementById()返回的是获取的标签 getElementByClassName()和getEl ...
- spark-sql(spark sql cli)客户端集成hive
1.安装hadoop集群 参考:http://www.cnblogs.com/wcwen1990/p/6739151.html 2.安装hive 参考:http://www.cnblogs.com/w ...
- H5的缓存 manifest
H5里面的App Cache是由开发Web页面的开发者控制的,而不是由Native去控制的,但是Native里面的WebView也需要我们做一下设置才能支持H5的这个特性. 1.工作原理 写Web页面 ...