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. linux部署的flask项目配置static

    环境: Python2.7 flask nginx linux的系统是Ubantu Python:我的是linux已经有的. flask:pip install flask nginx:sudo ap ...

  2. [LeetCode] Flip Game II 翻转游戏之二

    You are playing the following Flip Game with your friend: Given a string that contains only these tw ...

  3. eclipse主题之-------DevStyle

    最佳因为经常熬夜  eclipse自带的背景 白色 太伤眼了 换了其他颜色但是 总感觉 差点什么    所以就去eclipse自带的插件下载中心 下载了  DevStyle 其实 有很多的 主题插件的 ...

  4. Water Buying

    Water Buying time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. C#winform窗体实现对sql server数据库的增删改查

    1.运行效果截图 2.输入用户名,密码进行查询 查找成功则显示 查找不成功显示用户信息不存在 3.输入用户名与密码,向数据库中添加用户信息 添加后数据库表信息 4.查看全部信息 5.根据编号信息进行查 ...

  6. MySQL练习题2

    以下操作均在MySQL5.7数据库上实验无误 需要四张表 Student_new(Sid,Sname,Sage,Ssex)学生表 Sid:学号 Sname:学生姓名 Sage:学生年龄 Ssex:学生 ...

  7. Java远程连接redis, 报错 Connection refused: connect

    在今天的学习Redis中报错 Connection refused: connect 我总结了有三种情况: 1.远程服务器中的Redis没有开启. 2.远程连接地址出错,或者是端口出错. 3.远程服务 ...

  8. 解决 .net core 中 nuget 包版本冲突问题

    今天在一个 asp.net core 项目中遇到了 nuget 包版本冲突的问题,错误信息如下: Version conflict detected for Microsoft.AspNet.WebA ...

  9. webstorm 介绍

    最新版2017 破解 注册时,在打开的License Activation窗口中选择“License server”,在输入框输入下面的网址: http://idea.iteblog.com/key. ...

  10. MySQL慢查询日志总结 日志分析工具mysqldumpslow

    MySQL慢查询日志总结 - 潇湘隐者 - 博客园 https://www.cnblogs.com/kerrycode/p/5593204.html 2016-06-17 10:32 by 潇湘隐者, ...