C++文件流

博客展示了C++相关的效果图,但未提供更多关键信息。C++是后端开发常用语言,在众多领域有广泛应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C++文件流

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main() {
	ifstream ifs;
	ifs.open("main.cpp", ios::in);
	if (!ifs)
	{
		cout << "文件打开失败" << endl;
		return;
	}
	ofstream of;
	of.open("Output.txt", ios::out|ios::trunc);
	if (!of)
	{
		cout << "文件打开失败" << endl;
		return;
	}
	char str;
	int  c_count=0;
	int notNull=0;
	int letterCount=0;
	int letter = 0;
	double AvgCount=0.0;
	while (ifs.get(str))
	{
			cout << str;
			of.put(str);
			c_count++;
			if (str!=10&& str!=0 && str!=13&& str != 32)
			{
				notNull++;
			}
			if ((str >= 65 && str <= 90) || (str >= 97 && str <= 122))
			{
				letterCount++;	
				if (ifs.peek()<65|| (ifs.peek()>90&& ifs.peek()<97)||ifs.peek()>122)
				{
					letter++;
				}
			}				
	}
	cout << endl;
	cout << "字符总数:" << c_count << endl;
	cout << "非空白字符总数:" << notNull << endl;
	cout << "字母总数:" << letterCount << endl;
	cout << "平均单词长度:" << letterCount / letter << endl;
	ifs.close();
	of.close();
}

效果图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值