C++ Primer, Exercise 08-03,08_14,08_15,08_16
2012-11-12 13:29
274 查看
#include <iostream> #include <string> #include <sstream> #include <fstream> #include <vector> using namespace std; istream& readall(istream& is) { string str; while(is>>str) { cout<<str; } is.clear(); cout<<endl; return is; } ifstream& open_file(ifstream& in,const string &file) { in.close(); in.clear(); in.open(file.c_str()); return in; } void test08_14() { string s("006.txt"),outstr; ifstream is; open_file(is,s); while(is>>outstr) { cout<<outstr<<endl; } } void test08_15(string line) { stringstream strstream(line); readall(strstream); } void test08_16() { ifstream in; string s; open_file(in,"005.txt"); vector<string> vecline; while(getline(in,s)) { vecline.push_back(s); } for(vector<string>::iterator iter = vecline.begin(); iter!=vecline.end();iter++) { test08_15(*iter); } } int main() { test08_14(); test08_15("this is a test line for stringstream"); test08_16(); //readall(cin); return 0; }
相关文章推荐
- PSP(16/03/14-16/03/15)
- 15-03-14读书笔记
- P51第二章练习题14、15、16、17、18、19、20
- vb写的考试大题答案14,15,16,17,18
- Review_2012_11_13_11_14_11_15_11_16
- 阅读第13,14,15,16,17章
- 180中国跳棋(12)186(13)191(14)196(15)201(16)205(17)209.5(18)
- 读书笔记之《深入理解LINUX内核》13、14、15、16 章
- 《构建之法》13,14,15,16,17章读后感
- 读《构建之法》第13,14,15,16,17章
- (13)递增递减运算符 (14)字符串运算符 (15)赋值运算符 (16)switch case语句
- 13、14、15、16、17
- 阅读<构建之法>13、14、15、16、17章
- mit 计算机科学及编程导论(14,15,16)
- 《构建之法》13,14,15,16,17章读后感
- MIT differential equation---14,15,16
- Python每日练习 14 15 16 将某txt的内容写入到xls文件中
- 16 继承(三)(把前面14,15讲的情况结合起来)
- fedora14 15 16 apache mysql php yum安装
- 13-14-15-16-面向对象、继承、封装、struct和class