写入和读取文本文件的简单应用

mac2022-06-30  75

终于写了一些有用的代码,第一个是执行在999内挑选出水仙花数,并存入文件里,第二个是读取文件,显示内容。

 

 

 void out_file(){ int k=100,l,m,n,count=0; ofstream ofile; ofile.open("myfile.txt"); ofile<<"水仙花数有:"<<endl; do{ l=k/100; n=k; m=(k-l*100-n)/10; if(k==l*l*l+m*m*m+n*n*n){ ofile<<l<<"的3次方+"<<m<<"的3次方+"<<m<<"的3次方="<<k<<'/n'; count++; if(count%5==0)ofile<<endl; } k++; }while(k<9999); ofile<<endl; ofile.close(); } void in_file(){ char ch[256]; ifstream ifile; ifile.open("myfile.txt"); cout<<"文件内容:"<<endl; do{ ifile.getline(ch,255); cout<<ch<<endl; }while(ifile.eof()==0); ifile.close(); }  

转载于:https://www.cnblogs.com/J2EEPLUS/archive/2009/09/14/2487814.html

相关资源:编写一个java应用程序
最新回复(0)