c++面向对象编程
习题例子
Re:FusE
普通人
展开
-
统计文件中字符的个数
/* 编写一个函数int charnum(char fn[10]),该函数以只读方式打开文件fn,,通过统计,返回文件中字符的个数,请使用while循环实现计数功能。 注意:(1)部分源程序已存在文件中。 (2)请勿修改主函数main和其他函数中的任何内容,仅在函数charnum的花括号中填写若干语句。 (3)文件中的字符请使用ASCII字符。 */ #include<iostream...原创 2020-04-24 17:10:09 · 5233 阅读 · 0 评论 -
给文本文件每一行加行号
/* 打开指定的一个文本文件,在每一个行前加行号。 */ #include<iostream> #include<fstream> #include<stdlib.h> #include<iomanip> //cout<<setw() 输出格式控制 using namespace std; int main(){ /*(1)打开输...原创 2020-04-24 16:37:44 · 6611 阅读 · 6 评论 -
写出数据到文件中
#include<iostream> #include<fstream> using namespace std; void main(){ ofstream outfile;//L1 outfile.open("test1.txt");//outfile.open("test1.txt",ios::out); //默认方式//L2 //往"test1.txt...原创 2020-04-24 16:32:32 · 331 阅读 · 1 评论