练习8.4:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;int main() {//打开文件ifstream in("D:\\CCCCCCCCCCCCCCCCCCC\\yyhaif.txt");if (!in) {cerr << "无法打开输入文件" << endl;return -1;}string line;vector<string>words;while (getline(in, line)) {words.push_back(line);}in.close();//输入完毕,关闭文件vector<string>::const_iterator it = words.begin();while (it != words.end()) {cout << *it << endl;++it;}
}
练习8.5:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;int main() {//打开文件ifstream in("D:\\CCCCCCCCCCCCCCCCCCC\\yyhaif.txt");if (!in) {cerr << "无法打开输入文件" << endl;return -1;}string line;vector<string>words;while (in >> line) {words.push_back(line);}in.close();//输入完毕,关闭文件vector<string>::const_iterator it = words.begin();while (it != words.end()) {cout << *it << endl;++it;}
}
练习8.6:
暂时不会!!!