c++ 读取文件的内容

get.h

#ifndef _GET_H
#define _GET_H

#include <iostream>

std::istream& get(std::istream& in);

#endif

get.cpp

#include "get.h"

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." << std::endl;
			in.clear();
			in.ignore(200,'\n');
			continue;
		}
		std::cout << "输入的数据: " << ival << std::endl;
	}

	in.clear();

	return in;
}


猜你喜欢

转载自blog.csdn.net/empty_android/article/details/78613863