代碼如下://vc++6.0下運行。#include <iostream>#include <fstream>#include <stdlib.h>using namespace std;void main(){??? char ch;????????char sten[81]; ????fstream infile;????infile.open("File.txt",ios::in); ????if(infile.fail()){ cout<<"infile error!"; exit(1); } ????fstream outfile("TextFile.txt",ios::out|ios::in);????if(outfile.fail()){ cout<<"outfile error!"; exit(2); } ????while(!infile.eof()){ ? //把File中的小寫字母變?yōu)榇髮?,寫入TextFile。????????? infile.get(ch); ch=toupper(ch); outfile<<ch; ??? }
??????????????? infile.close();??? outfile.flush(); outfile.clear(); ??? outfile.seekg(0,ios::beg); ??? outfile.seekp(0,ios::beg); ??? int i=1;??? while(!outfile.eof()&&i<10){ ?//顯示TestFile的內(nèi)容,無i時會死循環(huán) ??????? outfile.getline(sten,81);????????cout<<i<<sten<<endl;??????? i++;??? } ??? outfile.close();}/*文件File.txt:When Day Is DoneIf the day is done ,If birds sing no more .If the wind has fiagged tired ,Then draw the veil of darkness thick upon me ,Even as thou hast wrapt the earth with The coverlet of sleep and tenderly closed ,The petals of the drooping lotus at dusk.From the traverer,Whose sack of provisions is empty before the voyage is ended ,Whose garment is torn and dust-laden ,Whose strength is exhausted,remove shame and poverty ,And renew his life like a flower underThe cover of thy kindly night .運行后:TextFile.txt:WHEN DAY IS DONEIF THE DAY IS DONE ,IF BIRDS SING NO MORE .IF THE WIND HAS FIAGGED TIRED ,THEN DRAW THE VEIL OF DARKNESS THICK UPON ME ,EVEN AS THOU HAST WRAPT THE EARTH WITH THE COVERLET OF SLEEP AND TENDERLY CLOSED ,THE PETALS OF THE DROOPING LOTUS AT DUSK.FROM THE TRAVERER,WHOSE SACK OF PROVISIONS IS EMPTY BEFORE THE VOYAGE IS ENDED ,WHOSE GARMENT IS TORN AND DUST-LADEN ,WHOSE STRENGTH IS EXHAUSTED,REMOVE SHAME AND POVERTY ,AND RENEW HIS LIFE LIKE A FLOWER UNDERTHE COVER OF THY KINDLY NIGHT ..*/
- 0 回答
- 0 關注
- 1642 瀏覽
添加回答
舉報
0/150
提交
取消