用C++实现,I/O流 文件的输入输出

来源:百度知道 编辑:UC知道 时间:2024/05/04 11:05:44
实验要求:编写程序功能实现:将文本文件中的内容复制到另一文本文件里,并将读出的内容显示在屏幕上。程序要求调试通过。

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{

ifstream in("Main.cpp"); //Main.cpp换成你读入的文件名(不同路径要加上全名)
ofstream out("CopyFile.txt");
char ch;
string str;
while( !in.eof() )
{
in.get(ch);
cout<< ch ;
str += ch;
}

cout<< endl;
out<< str ;

in.close();
out.close();
return 0;
}

#include "stdio.h"
main ()
{
FILE *in, *out;
char ch,infile[10], outfile[10];
printf ("Enter the infile name:");
scanf ("%s", infile);
printf ("Enter the outfile name:");
scanf ("%s", outfile);
if((in=fopen(infile,"r"))==NULL)
{
printf("cannot open infile\n");
exit(0);
}
if((out=fopen(outfile,"r"))==NULL)
{