用c写的,此程序经过调试,希望对你有所帮助:
#include
#include
#include
void main()
{
FILE *fp,*fq;
char a[100],*s;
if((fp=fopen("d:\\file1.txt","r"))==NULL)
{printf("can not open file!\n");exit(0);}
if((fq=fopen("d:\\file2.txt","w"))==NULL)
{printf("can not open file!\n");exit(0);}
fgets(a,10,fp);
s=strupr(a);/*库函数 strupr返回的是一个指针,将读取的字符窜转换成大写字母窜,不懂可以查阅课本*/
fputs(s,fq);
fclose(fp);
fclose(fq);
}
#include
#include
#include
#include
using namespace std;
void change( char& ch )
{
ch = toupper(ch);
}
int main()
{
ifstream ifs("file1.txt");
if( ifs.fail() )
return 1;
string str(( istreambuf_iterator
ifs.close();
for_each( str.begin(),str.end(),change );
ofstream ofs("file2.txt");
if( ofs.fail() )
return 1;
copy( str.begin(),str.end(),ostream_iterator
ofs.close();
return 1;
}