读入字符存入磁盘文件
2023-09-14 09:12:06 时间
1 #include <iostream> 2 #include <fstream> 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 void save_to_file() 6 { 7 ofstream outfile("f2.dat"); 8 if(!outfile) 9 { 10 cerr<<"open f2.dat error!"<<endl; 11 exit(1); 12 } 13 char c[80]; 14 cin.getline(c,80); 15 for(int i=0;c[i]!=0;i++) 16 if(c[i]>=65&&c[i]<=90||c[i]>=97&&c[i]<=122) 17 { 18 outfile.put(c[i]); 19 cout<<c[i]; 20 } 21 cout<<endl; 22 outfile.close(); 23 } 24 25 void get_from_file() 26 { 27 char ch; 28 ifstream infile("f2.dat",ios::in|ios::nocreate); 29 if(!infile) 30 { 31 cerr<<"open f2.dat error!"<<endl; 32 exit(1); 33 } 34 ofstream outfile("f3.dat"); 35 if(!outfile) 36 { 37 cerr<<"open f3.dat error!"<<endl; 38 exit(1); 39 } 40 while(infile.get(ch)) 41 { 42 if(ch>=97&&ch<=122) 43 ch=ch-32; 44 outfile.put(ch); 45 cout<<ch; 46 } 47 cout<<endl; 48 infile.close(); 49 outfile.close(); 50 } 51 int main(int argc, char** argv) { 52 save_to_file(); 53 get_from_file(); 54 return 0; 55 }
相关文章
- Java中将xml文件转化为json的两种方式
- VBA在多个文件中Find某字符的数据并复制出来
- tr - 转换或删除文件中的字符
- 文件输入输出处理(三)-字符流
- inputstreamreader读取文件_java读取字符串中每一个字符
- python基础3之文件操作、字符编码解码、函数介绍详解编程语言
- 数利用Linux查看文件字符数(linux统计文件字符)
- vs2015下C4819该文件包含不能在当前代码页(936)中表示的字符问题解决详解编程语言
- JSP JSTL <x:forEach>标签:遍历XML文件
- Linux文件快速查找字符的方法(linux文件中查找字符)
- Linux文件中字符的替换方式(linux文件字符替换)
- Linux下文件删除方法(删除文件linuxc)
- 使用Linux安装.run文件的详细步骤!(linux安装.run)
- 【深入探索:MySQL数据库文件之旅】(查看mysql数据库文件)
- 开启Linux之旅:学习字符设备文件(linux 字符设备文件)
- Linux字符连接:如何使用特殊字符将文本或文件连接到一起(linux 字符 连接)
- MySQL如何轻松导入大文件(mysql 导入 大文件)
- 在命令行下导入MySQL文件(cmd倒mysql文件)
- 本地文件无缝传入Redis(本地文件传入redis)
- MySQL 安装故障下载后找不到安装文件(mysql下载后没有文件)
- 文件 利用Oracle管理DBF文件的有效方式(oracle中的dbf)
- phpfeof用来识别文件末尾字符的方法
- 如何恢复SQLServer2000损坏的数据库文件