c++ primer 习题9.26

摘要: 阅读全文
posted @ 2013-01-17 14:09 wjungang 阅读(102) 评论(0) 推荐(0)

编写函数打开文件用于输入,将文件内容读入string类型的Vector容器,每一行存储为该容器对象的一个元素

摘要: #include <iostream>#include <fstream>#include <string>#include <vector>using namespace std;int fileToVector(string fileName, vector<string> &svec){ifstream inFile(fileName.c_str());if(!inFile){return 1;}string s;while(getline(inFile, s))svec.push_back(s);inFile.clos 阅读全文
posted @ 2013-01-14 16:21 wjungang 阅读(235) 评论(0) 推荐(0)

c++ primer 第8章 流状态 陷入死循环问题

摘要: #include <iostream>using namespace std;int main(){ int ival; while (cin >> ival, !cin.eof()) { if(cin.bad()) throw runtime_error("IO stream corrupted"); if (cin.fail()) { cerr << "bad data, try again" << endl; cin.clear(istream::goodbit);//cin.clear() cin. 阅读全文
posted @ 2013-01-14 09:46 wjungang 阅读(113) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示