第二十一章流 10使用命令行处理文件例程 简单

//第二十一章流 10使用命令行处理文件例程
/*#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char*argv[])
{
	if(argc==1)
	{
	    cout<<"访程序"<<argv[0]<<"未操作文件名"<<endl;
		exit(EXIT_FAILURE);
		//exit()函数就是退出程序,传入的参数是程序退出时的状态码,0表示正常退出,其他表示非正常退出
	}
	ifstream fin; //文件流读出操作
	long count;    //每一个文件的字符多少 
	long total=0; //总的文件字符长度
	char ch;
	for(int file=1; file<argc; file++)
	{
		fin.open(argv[file]);
		if(!fin.is_open())
		{
		   cout<<"不能打开文件"<<argv[file]<<endl;
		   fin.close();
		   continue;
		}
		count=0;
		while(fin.get(ch)){
		   count++;
		}
		cout<<count<<"字符在:"<<argv[file]<<endl;
		total+=count;
		fin.clear();//重置流状态
		fin.close();
	}
	cout<<total<<"所有文件中的字符合计"<<endl;
    return 0;
}*/

  

原文地址:https://www.cnblogs.com/xiangxiaodong/p/2709701.html