假设有一个叫 data.txt 的文件, 它包含以下内容: 

使用ifstream和getline读取文件内容[c++] ZZFry: One Jillion dollars.
使用ifstream和getline读取文件内容[c++] ZZ[Everyone gasps.]
使用ifstream和getline读取文件内容[c++] ZZAuctioneer: Sir, that's not a number.
使用ifstream和getline读取文件内容[c++] ZZ数据读取, 测试 。使用ifstream和getline读取文件内容[c++] ZZ

以下就是基于 data.txt 的数据读取操作:

使用ifstream和getline读取文件内容[c++] ZZ#include <iostream>
使用ifstream和getline读取文件内容[c++] ZZ#include <fstream>
使用ifstream和getline读取文件内容[c++] ZZ#include <string>
使用ifstream和getline读取文件内容[c++] ZZ
使用ifstream和getline读取文件内容[c++] ZZusing namespace std;
使用ifstream和getline读取文件内容[c++] ZZ
使用ifstream和getline读取文件内容[c++] ZZ//输出空行
使用ifstream和getline读取文件内容[c++] ZZvoid OutPutAnEmptyLine()
}

输出结果为:
Read from file: Fry:
Read from file: One
Read from file: Jillion
Read from file: dollars.
Read from file: [Everyone
Read from file: gasps.]
Read from file: Auctioneer:
Read from file: Sir,
Read from file: that's
Read from file: not
Read from file: a
Read from file: number.
Read from file: 数据读取,
Read from file: 测试
Read from file: 。
 

Read from file: Fry: One Jillion dollars.
Read from file: [Everyone gasps.]
Read from file: Auctioneer: Sir, that's not a number.
Read from file: 数据读取, 测试 。

Read from file: Fry: One Jillion dollars.
Read from file: [Everyone gasps.]
Read from file: Auctioneer: Sir, that's not a number.
Read from file: 数据读取, 测试 。

Error opening  dataFUNNY.txt for input
Press any key to continue
 
http://www.cnblogs.com/jcsu/articles/1190685.html
假设有一个叫 data.txt 的文件, 它包含以下内容: 

使用ifstream和getline读取文件内容[c++] ZZFry: One Jillion dollars.
使用ifstream和getline读取文件内容[c++] ZZ[Everyone gasps.]
使用ifstream和getline读取文件内容[c++] ZZAuctioneer: Sir, that's not a number.
使用ifstream和getline读取文件内容[c++] ZZ数据读取, 测试 。使用ifstream和getline读取文件内容[c++] ZZ

以下就是基于 data.txt 的数据读取操作:

使用ifstream和getline读取文件内容[c++] ZZ#include <iostream>
使用ifstream和getline读取文件内容[c++] ZZ#include <fstream>
使用ifstream和getline读取文件内容[c++] ZZ#include <string>
使用ifstream和getline读取文件内容[c++] ZZ
使用ifstream和getline读取文件内容[c++] ZZusing namespace std;
使用ifstream和getline读取文件内容[c++] ZZ
使用ifstream和getline读取文件内容[c++] ZZ//输出空行
使用ifstream和getline读取文件内容[c++] ZZvoid OutPutAnEmptyLine()
}

输出结果为:
Read from file: Fry:
Read from file: One
Read from file: Jillion
Read from file: dollars.
Read from file: [Everyone
Read from file: gasps.]
Read from file: Auctioneer:
Read from file: Sir,
Read from file: that's
Read from file: not
Read from file: a
Read from file: number.
Read from file: 数据读取,
Read from file: 测试
Read from file: 。
 

Read from file: Fry: One Jillion dollars.
Read from file: [Everyone gasps.]
Read from file: Auctioneer: Sir, that's not a number.
Read from file: 数据读取, 测试 。

Read from file: Fry: One Jillion dollars.
Read from file: [Everyone gasps.]
Read from file: Auctioneer: Sir, that's not a number.
Read from file: 数据读取, 测试 。

Error opening  dataFUNNY.txt for input
Press any key to continue

相关文章:

  • 2022-12-23
  • 2021-07-07
  • 2021-07-05
  • 2022-02-23
  • 2021-05-27
  • 2021-09-12
  • 2022-02-08
  • 2022-12-23
猜你喜欢
  • 2022-02-13
  • 1970-01-01
  • 2021-06-05
相关资源
相似解决方案