4.5
来源:互联网 发布:企业信息安全软件 编辑:程序博客网 时间:2024/05/17 06:52
/*
*编写一个函数,其唯一的形参和返回值都是istream&类型。
*该函数应一直读取流直到到达文件结束符为止
*还应该将读到的内容输出到标准输出中,
*最后,重设流使其有效,并返回流值。
*以cin为实参来调用测试函数
*/
#include "get.hpp"
#include <iostream>
using namespace std;
int main()
{
double dval;
get(cin);
cin >> dval;
cout << dval << endl;
return 0;
}
#ifndef GET
#define GET
#include <iostream>
std::istream& get(std::istream& in)
{
int ival;
while (in >>ival, !in.eof())
{
if (in.bad())
throw std::runtime_error ("IO stream corrupted");
if (in.fail())
{
std::cerr << "bad data, try again";
in.clear();
in.ignore(200,' ');
continue;
}
std::cout << ival << " ";
}
in.clear();
return in;
}
#endif
/*
*编写函数打开文件用于输入,、
*将文件内容读入string类型的vector容器,
*每一行存储为该容器对象的一个元素
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
ifstream ifcin;
vector<string> ivec;
string str;
ifcin.open ("D:\\wer.txt"); //在D盘下新建wer.txt,并输入字符。
if(!ifcin)
{
cerr << "open fail" << endl;
return -1;
}
while( !ifcin.eof ())
{
getline(ifcin,str);
ivec.push_back(str);
}
ifcin.close();
for(vector<string>::iterator iter = ivec.begin();iter != ivec.end();++iter)
{
cout << *iter <<endl;
}
system("pause");
return 0;
}
- 4.5
- 4.5
- 4.5
- 4.5
- 4.5
- 4.5
- 4.5
- 4.5
- 4.5
- 4.5~4.7
- 4.5晴
- 4.5 继承
- gcc 4.5
- 串4.5
- 4.5 包
- 4.5 多态
- 4.5-2
- javaSE 4.5
- (4)原型模式Prototype
- 划水系列(八)我在2013年编程之美全国挑战赛的资格赛中水水地做题
- 用css样式形成太极图
- C与C++的小知识
- 数组习(两种方法)
- 4.5
- 智力+贪心的过河问题
- 站得高才能看得远-再次认识ADO.NET
- [数据结构]第四章--串(读书笔记1)
- 人生还需要正能量
- playEffect参数的详解
- 转:微软老将Philip Su的离职信:回首12年职场生涯的心得和随笔
- 有趣的罗马数字
- Hibernate性能优化