文件读写

//============================================================================
// Name        : goodmorning.cpp
// Author      : byfei
// Version     :
// Copyright   : Your copyright notice
// Description : chemical in C++, Ansi-style
//============================================================================

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char* argv[])
{
	if(argc < 2)
	{
		cout<<"Don`t input filename";
		return 0;
	}
	FILE *fp = NULL;
	if((fp = fopen(argv[1],"r")) == NULL)
	{
		cout<<"File could not be opened"<<endl;
		return 0;
	}
	int test = 0;
	if(fscanf(fp,"%d",&test) != 1)
	{
		fclose(fp);
		return 0;
	}
	fclose(fp);

	for(int i=1;i<=test;++i)
	{
		int nResult = i%24;
		if(7<=nResult && nResult<=9)
			cout<<"Good Morning"<<endl;
		else
			cout<<"hello"<<endl;
	}
	return 0;
}



posted @ 2014-09-15 03:13  byfei  阅读(109)  评论(0编辑  收藏  举报