fstream实现文件复制(并将文件名小写改成大写)

 使用C++的fstream类来实现

 

char* filename = "C:\\grldr.mbr";//须复制文件路径     int len = strlen(filename);     while( *(filename+len-1)!='\\'){         len--;     }//获得文件名      char temp[32];     strcpy(temp,(filename+len));      for (int i = 0; i<=strlen(temp); i++)     {         char ch = temp[i];         if ( ch>='a'&&ch<='z')         {             temp[i] -= 'a'-'A';         }     }//修改大小写           ofstream outfile;//创建文件     outfile.open(temp,ios::out|ios::binary);          ifstream infile;//读入待复制文件     infile.open(filename,ios::in|ios::binary);     if (infile.is_open())     {         char ch;         infile.get(ch);         while(!infile.eof()){//eof文件结束标志             outfile<<ch;             infile.get(ch);         }         infile.close();     }            outfile.close();

 

你可能感兴趣的:(C++,文件复制,fstream, , )